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 false positive with Generator when yield is in a "while" condition #286
Fix false positive with Generator when yield is in a "while" condition #286
Conversation
when determining if scope has yield or not.
@@ -396,6 +396,12 @@ public function bodySpecifiedVoidTReturn3(): \Generator | |||
return 2; | |||
} | |||
|
|||
public function yieldInExpression(): \Generator |
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.
The issue reported was detected by the MissingReturn rule. Not sure if there is a more suitable way to test (the test is that there is no error).
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.
Thank you, looks like the right fix! (I'm sorry for the current build failures on master, will fix them once I have a working computer again this week.)
Could you please also verify that other similar statements (for loop, foreach loop, do while, switch) don't have the same problem? THanks.
$exprResult = $this->processExprNode($loopExpr, $bodyScope, static function (): void { | ||
}, ExpressionContext::createTopLevel()); | ||
$bodyScope = $exprResult->getScope(); | ||
$hasYield = $hasYield || $exprResult->hasYield(); |
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.
not sure why this is a special case - i guess we could also get the no, ExpressionResult
before this loop on $stmt->loop
loop
is an array of the 3 expressions I guess.
tests/e2e/magic-setter/test.php
Outdated
<?php // lint >= 7.4 | ||
<?php declare(strict_types = 1); | ||
|
||
// lint >= 7.4 |
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 was the cs fixer
@ondrejmirtes updated for |
Looks like a simple if statement can't handle it either: https://phpstan.org/r/5dafc496-79af-4719-bcf2-41fa369da313 |
indeed, added |
Thank you! |
Relates to: phpstan/phpstan#3669
This PR fixes the above named issue as suggested there.
Not sure about the test however.