-
Notifications
You must be signed in to change notification settings - Fork 462
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
Use argument types as parameter types for inline closures (#7798) #1628
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 is really nicce and almost perfect! The only thing missing is that you should also test and make sure it works for arrow functions :) Please add another gathered file in NodeScopeResolverTest, but only for PHP_VERSION_ID >= 70400
.
019b63d
to
366e330
Compare
Thanks for the feedback, much appreciated. I've now added support and tests for arrow functions as well. I've duplicated the logic and added another NodeVisitor, as |
Thank you! |
The functionality was introduced in phpstan#1628. It works. But as soon as you use an inline assign expression it breaks. Let's support this case too. Sometimes, you want to call something inline and also use the callback later.
The functionality was introduced in #1628. It works. But as soon as you use an inline assign expression it breaks. Let's support this case too. Sometimes, you want to call something inline and also use the callback later.
Implements #7798. Thank you for your advise, it was very helpful.
This unfortunately is not used for this case;
$passedToType
is only passed toprocessClosureNode
when handling a closure as a function argument:phpstan-src/src/Analyser/NodeScopeResolver.php
Lines 3223 to 3226 in 4b6d964
phpstan-src/src/Analyser/NodeScopeResolver.php
Lines 2220 to 2221 in 4b6d964
Because the closure is never the argument (it is the
name
of theFuncCall
), this case is slightly different than forarray_map
, as theExpr\Closure
is never handled byParametersAcceptorSelector::selectFromArgs
(only itsClosureType
is).Please let me know if I misunderstood.