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
Infer closure type from context #740
Comments
Psalm can’t currently infer closure types depending on how those closures are used. Evaluation for function/method calls is:
In your example it would possible to figure out the types in step 1, but not if the param order was swapped. In that scenario, there’d have to be another sweep to collect all templated types in args, and solve for x (or T, here) |
@muglug could you provide example with swapped param order? I don't quite understand. |
Sorry, let this one slip. $gen = filter($collection, function ($item){
return $item->check(13);
}); could work because we'd identify that But reverse the parameters so the closure is the first arg, and Psalm wouldn't know what to do: $gen = filter(function ($item){
return $item->check(13);
}, $collection); Now To solve this we'd have to do a second pass to resolve all templated types, and that's not massively ideal. |
See reply here: #742 (comment) - I think they're the same issue, and I don't think it's fixable |
It's not quite the same issue, actually. Going to reopen, sorry. |
But nevertheless, after a bunch of thought, I don't think this is worth my effort to fix (beautiful as it would be) |
Let's say we have simple function
Right now psalm is unable to infer types for closure from this declaration
example:
https://getpsalm.org/r/1a8f1377b0
The text was updated successfully, but these errors were encountered: