Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sprintf() inference for constant values with format-width in pattern #3474

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 23, 2024

we should not infer constant strings 1:1 when sprintf expects a format-width which can add padding characters and what-not.


fixes wrong constant value inference
https://phpstan.org/r/ea3080f4-f032-4f2f-8f3b-c5c0f0062da0
https://3v4l.org/HI0pE

We could make this more precise but I fixed only what is blocking #3475

@staabm staabm marked this pull request as ready for review September 23, 2024 19:27
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

Comment on lines +107 to +108
$matches['specifier'] === 's'
&& ($checkArgType->isConstantValue()->no() || $matches['width'] === '')
Copy link
Contributor Author

@staabm staabm Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual fix is here. everything else is refactoring/making code easier to read

staabm and others added 3 commits September 26, 2024 08:59

Verified

This commit was signed with the committer’s verified signature.
thg2k Giovanni Giacobbi
@ondrejmirtes ondrejmirtes merged commit 31362eb into phpstan:1.12.x Sep 26, 2024
278 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the sprintf-refac branch September 26, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants