- Notifications
You must be signed in to change notification settings - Fork 545
Fix array_filter with non-empty result #315
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
Conversation
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.
This isn't what I suggested. Keep the test but try to fix ConstantArrayType::generalize() implementation instead. It just needs to do TypeCombinator::intersect(new ArrayType(...), new NonEmptyArrayType()); instead on the last line.
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.
When looking more into it I realized that your suggestion is actually incorrect. I added a test which would break in your case:
function dummy4(?DateTimeInterface $date): void { assertType('DateTimeInterface|false', min(array_filter([$date]))); }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.
My suggestion is necessary, non empty constant array needs to be generalized into a non empty general array. But it might not be sufficient to fix this bug and something else needs to be done in the extension too.
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.
Alright. Check this commit please if it is what you want.
It will most likely break the ArrayFilterFunctionReturnTypeReturnTypeExtension again so I'll look into it. Just wanna know if the ConstantArrayType fix is correct.
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.
It broke a bunch of other tests though...
| Ah. I get it now. Sorry, I was doing it in a hurry. I'll get back to it later. |
0dad8f7 to d1f038e Compare fc00482 to f26514d Compare | Yeah, so the actual fix in |
| In that case would you consider merging my changes to |
| I tried but... I'm afraid that I can't fix the |
| Simply put, the |
| Superseded by: d67dae3 |
phpstan/phpstan#3752