fix: some functions falsely detected as generators#1479
Merged
Ocramius merged 1 commit intoRoave:6.54.xfrom Jan 25, 2025
Merged
fix: some functions falsely detected as generators#1479Ocramius merged 1 commit intoRoave:6.54.xfrom
Ocramius merged 1 commit intoRoave:6.54.xfrom
Conversation
Ocramius
requested changes
Jan 25, 2025
Member
Ocramius
left a comment
There was a problem hiding this comment.
Need to apply CS (and ideally squash that commit, please)
| $nodeProperty = $node->$nodeName; | ||
|
|
||
| if ($nodeProperty instanceof Node && $this->nodeIsOrContainsYield($nodeProperty)) { | ||
| if ($nodeProperty instanceof Node && |
Member
There was a problem hiding this comment.
Operator precedence making this a bit of a puzzle to read: let's add some parentheses, please 😁
| ['<?php function foo() { yield from []; }', true], | ||
| ['<?php function foo() { return fn () => yield $foo; }', false], | ||
| ['<?php function foo() { return function () { yield $foo; }; }', false], | ||
| ['<?php function foo() { return new class () { function bar() { yield $foo; } }; }', false] |
Member
There was a problem hiding this comment.
I think we even had a PR discussion about this, last year: thanks for fixing this pothole!
d93f26c to
63c18ae
Compare
…es containing yield expressions falsely detected as generators
63c18ae to
67a14ab
Compare
Ocramius
approved these changes
Jan 25, 2025
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.
Relates to phpstan/phpstan-src#3794 and phpstan/phpstan#12462.
@ondrejmirtes asked me to submit an according fix here as well.
The proposed changes fix functions returning closures, arrow functions or anonymous classes containing yield expressions to be falsely recognized as generators.