Remove array_filter mixed handling which breaks type specification #1012
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adapts
ArrayFilterFunctionReturnTypeReturnTypeExtension
to not handle a mixed argument anymore with aBenevolentUnionType
.This fixes truthy type specification with
is_array && array_filter
if the input is mixed, but I guess this is just a side-effect and there might be a better fix..Context / use case: phpstan/phpstan-webmozart-assert#101
Without the modifications here I'd get
BUT I'm also aware that the changes here might be negatively affecting
array_filter
behaviour pre PHP 8, see https://3v4l.org/sOWbb. Is there a better / more pragmatical way to improve this? On the other hand, is PHPStan actively supporting PHP quirks with warnings and such?The main problem / limitation that I have is apparently how
TypeSpecifier
handles the BooleanAnd expression.IsArrayFunctionTypeSpecifyingExtension
in https://github.com/phpstan/phpstan-src/blob/1.4.6/src/Analyser/TypeSpecifier.php#L608 and makes PHPStan aware that my input var is of type ArrayType, which is goodAny other ideas how to improve that? It looks like NodeScopeResolver is handling this a bit different and not loosing the information so to say. Or I'm misunderstanding it somehow :)