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

Incremented numeric-string should change to int/float #2797

Merged
merged 14 commits into from Apr 5, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 29, 2023

* @param numeric-string $ns
*/
function doFoo(string $s, $ns, float $f) {
assertType('string', ++$s);
Copy link
Contributor

Choose a reason for hiding this comment

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

++$s will be an int even if the input value is a string. https://3v4l.org/i4rru

refs phpstan/phpstan#10187

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great catch, thx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please have another look, I think it should look better now

@staabm staabm marked this pull request as draft December 4, 2023 10:50
@staabm staabm marked this pull request as ready for review December 4, 2023 12:34
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Dec 4, 2023

I have tested locally that the error in phpstan/phpstan#10187 no longer happens as requested.
if required I can send a strict-rules UselessCastRuleTest regression test, but it feels not necessary.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Please add regression test for 10187.

@@ -102,7 +102,7 @@
'str_ends_with' => ['bool', 'haystack'=>'string', 'needle'=>'string'],
'str_starts_with' => ['bool', 'haystack'=>'string', 'needle'=>'string'],
'strchr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'before_needle='=>'bool'],
'stripos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int'],
'stripos' => ['0|positive-int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to have the same return type across php versions, so we don't need to ignore different errors per php version

@staabm
Copy link
Contributor Author

staabm commented Mar 30, 2024

took me a few attempts to get this work across php versions.. but it should work now

@staabm staabm marked this pull request as ready for review March 30, 2024 14:47
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 59c3eaa into phpstan:1.10.x Apr 5, 2024
441 of 443 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants