Use argument types as parameter types for inline closures (#7798)#1628
Merged
ondrejmirtes merged 1 commit intophpstan:1.8.xfrom Aug 17, 2022
Merged
Use argument types as parameter types for inline closures (#7798)#1628ondrejmirtes merged 1 commit intophpstan:1.8.xfrom
ondrejmirtes merged 1 commit intophpstan:1.8.xfrom
Conversation
ondrejmirtes
requested changes
Aug 16, 2022
Member
ondrejmirtes
left a comment
There was a problem hiding this comment.
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
Contributor
Author
|
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 |
ondrejmirtes
approved these changes
Aug 17, 2022
Member
|
Thank you! |
ruudk
added a commit
to ruudk/phpstan-src
that referenced
this pull request
Oct 8, 2024
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.
ondrejmirtes
pushed a commit
that referenced
this pull request
Oct 9, 2024
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements #7798. Thank you for your advise, it was very helpful.
This unfortunately is not used for this case;
$passedToTypeis only passed toprocessClosureNodewhen 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
nameof theFuncCall), this case is slightly different than forarray_map, as theExpr\Closureis never handled byParametersAcceptorSelector::selectFromArgs(only itsClosureTypeis).Please let me know if I misunderstood.