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
Incorrect type simplification when combining mixed[] and iterators #4566
Comments
Hi, this is a complicated heuristic mainly for legacy code that uses |
Thanks for providing context, however could you consider reopening this issue? This heuristic results in the following unpredictable behaviour:
The reason I raised this in the first place is because of a Doctrine changing a bunch of IMO this behaviour should be removed, even if users can opt-out of it right now that would be an improvement. As you say in your reply people can fix incorrect vendor code using stubs, but what you're telling me to do is fix non-broken code. FWIW Psalm appears to have an option for this: https://psalm.dev/docs/running_psalm/configuration/#allowphpstormgenerics Right now it seems with PHPStan using the |
Can you show the specific error you're getting when working with Doctrine reproduced on phpstan.org? |
This seems to be as simple as I can make it without copying loads of code from Doctrine: https://phpstan.org/r/dcfed621-3978-4d3f-a4b9-73647ecf7c18 |
Doctrine's PHPDoc is simply wrong. This is sufficient to make it right: https://phpstan.org/r/e85c863a-2c4f-4e55-814c-d3eb1be52bed Please send Doctrine a PR, or override it in your codebase with a stub file. |
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
Type declaration
\Iterator<array-key,mixed>|mixed[]
is incorrectly simplified toiterable&Iterator<(int|string), mixed>
instead ofiterable<(int|string), mixed>
. You can see in the below example thatiterable<array-key,mixed>
instead ofmixed[]
works around the problem.https://phpstan.org/r/ff2f9b51-429c-46de-8bea-fe9728bca69b
Code snippet that reproduces the problem
https://phpstan.org/r/f682ea7b-5cb7-4e91-a1c9-33e9daa0ca50
Expected output
Expected no error.
The text was updated successfully, but these errors were encountered: