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
Fix array_filter with callback that always evaluates to false #939
Fix array_filter with callback that always evaluates to false #939
Conversation
Nope, it should be an empty ConstantArrayType 😊 |
ah forgot that the tests still need to run with older PHP versions too.. |
thought about that too hmm, I was afraid it might mess things up if e.g. later on elements are added again. Update: tested and seems to be behaving just fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it
The remaining failing checks (5x phpstan-doctrine OOM, 1x composer) are the same I saw elsewhere too IIRC, should be fine. |
I added more tests for already existing, unchanged behaviour. Hope that's fine. My plan is to refactor and add features in 1 or 2 follow-up PRs and already existing tests would be very useful then :) |
Thank you! |
Fixes the return type narrowing if the callback evaluates to false. E.g. an
int[]
array is used together with ais_string
callback. In that case the filtered type inArrayFilterFunctionReturnTypeReturnTypeExtension
would bearray<*NEVER*>
which does not make sense.We found this in https://github.com/phpstan/phpstan-src/pull/938/files#r790184831.