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
False array type specification adding foreach #7144
Labels
Comments
rajyan
changed the title
False positive array type specification using foreach
False array type specification adding foreach
Apr 28, 2022
@rajyan After the latest commit in 1.7.x, PHPStan now reports different result with your code snippet: @@ @@
10: Dumped type: array{foo?: array<string>, bar?: array<string>}
11: Offset 'bar'|'foo' does not exist on array{foo?: array<string>, bar?: array<string>}.
21: Dumped type: array{foo?: array<string>, bar?: array<string>}
-31: Dumped type: array<'bar'|'baz'|'foo', array<string>>
+31: Dumped type: array{foo?: array<string>, bar?: array<string>}
+32: Offset 'bar'|'baz'|'foo' does not exist on array{foo?: array<string>, bar?: array<string>}. Full report
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Bug report
Another related issue for #7000
Adding foreach make a wrong assumption on array type.
Code snippet that reproduces the problem
https://phpstan.org/r/f2f27d58-21fa-480c-a284-d70777f19926
The problem is described in
test3
. The addition of key in line 30 (compared totest1
) and addition of foreach in line 32 (compared totest2
) makes the type of$arr
asarray<'bar'|'baz'|'foo', array<string>>
which I think is not correct.Expected output
Addition of foreach should not change the array type.
Also, it should report on line 32 for non existing offset access.
Did PHPStan help you today? Did it make you happy in any way?
Yes! 😄
The text was updated successfully, but these errors were encountered: