-
Notifications
You must be signed in to change notification settings - Fork 510
Add failing test cases #1049
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
Add failing test cases #1049
Conversation
I think I found a simple fix by not further specifying types if both sides are CallLike nodes. I initially wanted to somehow check if they are "equal" nodes (e.g. having the same name and args or so), but not sure if this is really needed or makes sense. |
Need to investigate/fix callables that resolve to a constanttype still |
Nevermind, added the ConstantType behaviour I was thinking of, to me it's looking good now. Time to get more sleep.. |
628e1d1
to
4c17f02
Compare
I've just submitted a failing test - a counter example that shows we can really do this only for the same Variables on both sides. So please update the code to reflect it. The problem with CallLikes is more complicated. I don't think it's worth diving into this to actually solve it. Just to outline this - we could say that |
Thank you. This is still tricky I think. Limiting the new parts to Variables only fixes the notSame bugs, yes. But there are still 2 problems
|
…sides are CallLike nodes
This leaves us only the same bugs that were already there.
979c4e9
to
95e510b
Compare
b9ec85c
to
2286ff4
Compare
2286ff4
to
94d9b6c
Compare
OK, I finally got something useful. How I came to this I tried to not mess around too much and keep the diff readable, but well, it's not optimal. With whitespace changes hidden it's okayish. The last failing test is hopefully not related, but I'm not a 100% sure. Why would only this suddenly fail? The error looks valid at least, I'll take a look tomorrow in composer if I broke or fixed something. Ah I forgot, running 1) PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRuleTest::testRule
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
78: Call to method ImpossibleMethodCall\Foo::isSame() with stdClass and stdClass will always evaluate to true.
81: Call to method ImpossibleMethodCall\Foo::isNotSame() with stdClass and stdClass will always evaluate to false.
84: Call to method ImpossibleMethodCall\Foo::isSame() with *NEVER* and stdClass will always evaluate to false.
+95: Call to method ImpossibleMethodCall\Foo::isSame() with stdClass and stdClass will always evaluate to true.
+98: Call to method ImpossibleMethodCall\Foo::isNotSame() with stdClass and stdClass will always evaluate to false.
101: Call to method ImpossibleMethodCall\Foo::isSame() with 'foo' and 'foo' will always evaluate to true.
104: Call to method ImpossibleMethodCall\Foo::isNotSame() with 'foo' and 'foo' will always evaluate to false.
+107: Call to method ImpossibleMethodCall\Foo::isSame() with mixed and mixed will always evaluate to true.
+110: Call to method ImpossibleMethodCall\Foo::isNotSame() with mixed and mixed will always evaluate to false.
113: Call to method ImpossibleMethodCall\Foo::isSame() with array{} and array{} will always evaluate to true.
116: Call to method ImpossibleMethodCall\Foo::isNotSame() with array{} and array{} will always evaluate to false.
119: Call to method ImpossibleMethodCall\Foo::isSame() with array{1, 3} and array{1, 3} will always evaluate to true. |
Oh, I'm really happy with this, the diff makes total sense :) The one new failure in composer repo (https://github.com/phpstan/phpstan-src/runs/5435424726?check_suite_focus=true) looks something that we changed here and is related because It's related to the type alias: https://github.com/composer/composer/blob/575fbfb53fcc2388916d554271c99c8281fea782/src/Composer/Package/Version/VersionGuesser.php#L31 Can you please reproduce it here in a unit test? Even if it's right or wrong, we want it detected. |
I can do that, but what really confuses me is that I seem to be able to reproduce it on master already? But I'm gonna add the test and see how it behaves locally. |
…d via composer/composer
Aah ok I think I got it, the error is different. 1) PHPStan\Rules\Arrays\NonexistentOffsetInArrayDimFetchRuleTest::testRule
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
436: Cannot access offset 'foo' on 42.
439: Cannot access offset 'foo' on 4.141.
443: Cannot access offset 'foo' on array|int.
-504: Offset 'feature_pretty…' does not exist on array{version: string, commit: string|null, pretty_version: string|null, feature_version: non-empty-string, feature_pretty_version?: string|null}.
+504: Offset 'feature_pretty…' does not exist on array{version: non-empty-string, commit: string|null, pretty_version: string|null, feature_version: non-empty-string, feature_pretty_version?: string|null}.
' I guess this shows me that there are more expression nodes, additional to a simple Variable, where I can specify more. Let me check. |
Adapted, if I'm lucky the build should be green now. But I think the new I think I liked the "dumber" version with the limitation to Variable expressions more :) I'll take another look later and at least will add multiple level dimfetch support with a NodeScopeResolver test. Also have an idea to make it stricter and safer. That's easy and will be better than the current workaround |
Yeah, the fix doesn't seem right :) What's the nature of the problem in Composer? Is it even a bug? |
In Composer there is a non-existant array offset access which is correctly reported by PHPStan. And baselined in Composer. But on master the === with the ArrayDimFetch nodes is specified while here it wasn't any more. And that changes the types PHPStan is aware of in the array which changes the error message in the baseline (non-empty-string vs string). |
…DimFetch / array offset
I think that's the best I can come up with for now. Let me know what you think. Also, the |
I took your tests and I'm trying an alternative approach: #1058 Let's see how it fares in CI :) What I don't like in this PR is the instanceof of another Node besides Variable, seems too specific to just fix the Composer issue. The main thing I want to do in my PR is "Consider |
1 similar comment
I took your tests and I'm trying an alternative approach: #1058 Let's see how it fares in CI :) What I don't like in this PR is the instanceof of another Node besides Variable, seems too specific to just fix the Composer issue. The main thing I want to do in my PR is "Consider |
Took me forever to just create those tests. The reason was that I used only
createStdClass()
before and it never failed for theisNotSame
. The reason for that was https://github.com/phpstan/phpstan-src/blob/1.4.8/src/Rules/Comparison/ImpossibleCheckTypeHelper.php#L191 because the expressioncreateStdClass()
was already specified in the scope from theisSame
.. Which is why I added those strings.The
isNotSame
was broken by #1046But the
isSame
was already broken before. The problem is the true scope intersection of types just a bit further up.Limiting it to variable nodes would break
isSame(1, 3)
expressions. Apparently limiting it to not beingCallLike
nodes seems to do the trick, but this feels still wrong to me.Leaving this here for now and I'll come back to it after having a thought.
Refs phpstan/phpstan-phpunit#120 and phpstan/phpstan-webmozart-assert#122