-
Notifications
You must be signed in to change notification settings - Fork 134
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
fix: some functions falsely detected as generators #1479
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.
Need to apply CS (and ideally squash that commit, please)
@@ -360,7 +362,11 @@ private function nodeIsOrContainsYield(Node $node): bool | |||
foreach ($node->getSubNodeNames() as $nodeName) { | |||
$nodeProperty = $node->$nodeName; | |||
|
|||
if ($nodeProperty instanceof Node && $this->nodeIsOrContainsYield($nodeProperty)) { | |||
if ($nodeProperty instanceof Node && |
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.
Operator precedence making this a bit of a puzzle to read: let's add some parentheses, please 😁
@@ -236,6 +236,9 @@ public static function generatorProvider(): array | |||
['<?php function foo() { $foo->func(yield $foo); }', true], | |||
['<?php function foo() { new Foo(yield $foo); }', true], | |||
['<?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] |
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.
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
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.
Thanks @sebkehr!
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.