-
Notifications
You must be signed in to change notification settings - Fork 504
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 false positive when type casting in IF statement #3431
Conversation
This pull request has been marked as ready for review. |
@@ -63,6 +63,12 @@ function castInt($x, string $s, bool $b) { | |||
assertType('false', $b); | |||
} | |||
|
|||
if ((int) $s) { | |||
assertType('string', $s); // could be *NEVER* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reachable for 1
or 01
, numeric-string&non-falsy-string
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we reach ELSE for '0.1'
which is a numeric string - https://3v4l.org/NeugB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and not for 1.5
- https://3v4l.org/VBPn2 - so string
is best or something like string~(''|'0')
?
also notice 1x
- https://3v4l.org/PGs9f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string~(''|'0')
is non-falsy-string
. but I think we are in crazy territory land where string
should be good enough ;)
d9a447b
to
a89399d
Compare
@@ -134,10 +134,6 @@ public function testBug11674(): void | |||
'Elseif condition is always false.', | |||
28, | |||
], | |||
[ | |||
'Elseif condition is always false.', | |||
36, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a while but I found the bad boy for which the elseif can be false: https://3v4l.org/p1sON
I think this logic in TypeSpecifier makes more sense. Before the issue we didn't know that we can't compare all the casts to We lost precision in a few cases but now it's up to |
Thank you. |
thank you! |
closes phpstan/phpstan#11674
see https://3v4l.org/NeugB