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
Foreaching an Iterable<Key, NonNullType>
never results in null
#3763
Comments
Iterable
never results in null
Iterable<Key, NonNullType>
never results in null
It seems like the foreach type is being inferred from the return type of |
In line with PHP's own iterators, it's my belief that |
This is IMO not a bug, this is something PHPStan should check. There is no official documentation how current should behave and the internal behaves the way it returns a null in invalid state, but the general logic approach here is to throw (InvalidStateException) in invalid state. Ie. current should return only valid values, otherwise a check via valid() call is needed. |
@dktapps After the latest commit to dev-master, PHPStan now reports different result with your code snippet: @@ @@
+17: Method Iterable1::current() should return NamedTag|null but returns NamedTag|false.
49: Cannot call method getValue() on NamedTag|null. Full report
|
@dktapps After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-49: Cannot call method getValue() on NamedTag|null.
+17: Method Iterable1::current() should return NamedTag|null but returns NamedTag|false. Full report
|
I think this works as expected now. |
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. |
Bug report
Code snippet that reproduces the problem
https://phpstan.org/r/807ccb92-293e-4443-9a37-90d210e75a89 (execution: https://3v4l.org/SWnXd)
Expected output
Zero errors.
The text was updated successfully, but these errors were encountered: