Skip to content

Commit 2d035a9

Browse files
dantleechondrejmirtes
authored andcommitted
Handle yield in if
1 parent d4c5dcb commit 2d035a9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ private function processStmtNode(
676676
$exitPoints = [];
677677
$finalScope = null;
678678
$alwaysTerminating = true;
679-
$hasYield = false;
679+
$hasYield = $condResult->hasYield();
680680

681681
$branchScopeStatementResult = $this->processStmtNodes($stmt, $stmt->stmts, $condResult->getTruthyScope(), $nodeCallback);
682682

@@ -685,7 +685,7 @@ private function processStmtNode(
685685
$branchScope = $branchScopeStatementResult->getScope();
686686
$finalScope = $branchScopeStatementResult->isAlwaysTerminating() ? null : $branchScope;
687687
$alwaysTerminating = $branchScopeStatementResult->isAlwaysTerminating();
688-
$hasYield = $branchScopeStatementResult->hasYield();
688+
$hasYield = $branchScopeStatementResult->hasYield() || $hasYield;
689689
}
690690

691691
$scope = $condResult->getFalseyScope();

tests/PHPStan/Rules/Missing/data/missing-return.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ public function yieldInForeach(): \Generator
420420
}
421421
}
422422

423+
public function yieldInIf(): \Generator
424+
{
425+
if (yield 1) {
426+
}
427+
}
428+
423429
}
424430

425431
class VoidUnion

0 commit comments

Comments
 (0)