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
array_filter inference broken for arrow functions #2627
Labels
Comments
Yes, if the comment is there, no issues. But if the dummy is removed I get this:
|
muglug
changed the title
proposal: adjust type returned by array_filter infered from the filter callback
array_filter inference broken for arrow functions
Jan 15, 2020
This is a simple bug – there's different behaviour for arrow functions: https://psalm.dev/r/2cb63c9069 |
I found these snippets: https://psalm.dev/r/2cb63c9069<?php
class A {}
class B {}
$a = \array_filter(
[new A(), new B()],
function($x) {
return $x instanceof B;
}
);
$b = \array_filter(
[new A(), new B()],
fn($x) => $x instanceof B
);
echo $a;
echo $b;
|
@muglug Aha nice, when I dont use arrow function, it is ok without the dummy comment. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have this piece of code that filters an array<A|B> based on value type effectively restricting the return type of the array_filter call to array. Psalm is not able to infer this type reduction and so I have to introduce a variable and add comment informing psalm (and anyone else) that array is the actualy type returned by array_filter
It would be nice if psalm could infer the type, but I have no idea if that's even possible...
PS: PHP 7.4 arrow functions are used in the snippet but that is not necesary to reproduce the problem I believe
The text was updated successfully, but these errors were encountered: