-
-
Notifications
You must be signed in to change notification settings - Fork 947
False positive: Parameter x of function y expects z, *NEVER* given #5474
Description
Bug report
When you perform an equality check between arrays, it turns the data types of the arrays to "NEVER" if they are identical, within the scope of the conditional. This seems strange as I'd expect unreachable code errors but either way it works. (So line 22 should report an error rather than the NEVER on line 23)
However, if you don't use literals and compare against a RETURNED array that has a shape, it cannot know if it will at runtime be different or not. But it still turns into NEVER. The exact same comparison but without one side being wrapped in a function works fine.
In summary: The error on line 31 should not be there. The error on line 23 is confusing and it should be an impossible message on 22.
No issue with non-identity comparison "!=".
Code snippet that reproduces the problem
https://phpstan.org/r/93c01ef0-94da-41cb-818b-e9628ba65649
Expected output
No errors.
Did PHPStan help you today? Did it make you happy in any way?
It helped me today, yesterday, the day before, and I've happily worked around this for now using != instead of !== so you can resolve in your own time 👍