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
Retain left and right types in equal expression #1046
Retain left and right types in equal expression #1046
Conversation
Maybe I'm too dumb today but I need to see what this changes via a NodeScopeResolverTest case :) |
I'm also not sure yet if this makes sense, I'm still playing around with it and need some more time. Should have waited with the PR a bit longer |
3dc9167
to
3341fde
Compare
tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleTest.php
Show resolved
Hide resolved
f266748
to
ade7898
Compare
fbf6c86
to
9a37023
Compare
Alright, why does this work? 😂 Where's the exception to treat |
Yeah, let me get back to that at a later time, I can't figure this out today I'm afraid |
Maybe first open a PR that just adds the test cases that already work on master (and comment those that do not work). Then the situation will be more transparent maybe. |
I'm not quite sure I understand what the problem is? What do you think should be different here in regad to |
It makes sense but I have no idea why it works. |
AFAIK |
Ah, so the same expression on left/right creates a contradiction inside the SpecifiedTypes leading to NeverType in the |
That'd make sense :) |
I did confirm this now. For the true scope / if branch we get the stdClass ObjectType as left and right sureTypes. And those are unionized. No surprises there. For the false scope / else branch we get the stdClass ObjectType as left and right sureNotTypes. And those are normalized to NeverTypes (using your improved normalization which makes use of the scope and removes stdClass from stdClass) which are then intersected. |
Great, I'll merge this if you mark it as ready :) |
Thank you. |
This is not really changing much.. It's an adaption very similar to #1021
Equal
expressions are, among other things, converted toIdentical
expressions if possible for the left and right types. If not, then no types at all are specified. This change modifies that, so that at least the left and right types are retained.The first new test case was already working (because
$int == (int) $int
) is safe to be converted to an Identical expression. The second new test case is affected by this change, previously no types at all were specified. I'm mostly doing this so that we have more type information and strict impossible checks, as reported in e.g. phpstan/phpstan-webmozart-assert#32, do not fail