Skip to content

Commit 412cc04

Browse files
dantleechondrejmirtes
authored andcommitted
yield in switch
1 parent 2d035a9 commit 412cc04

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/Analyser/NodeScopeResolver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,14 @@ private function processStmtNode(
10131013
[]
10141014
);
10151015
} elseif ($stmt instanceof Switch_) {
1016-
$scope = $this->processExprNode($stmt->cond, $scope, $nodeCallback, ExpressionContext::createDeep())->getScope();
1016+
$condResult = $this->processExprNode($stmt->cond, $scope, $nodeCallback, ExpressionContext::createDeep());
1017+
$scope = $condResult->getScope();
10171018
$scopeForBranches = $scope;
10181019
$finalScope = null;
10191020
$prevScope = null;
10201021
$hasDefaultCase = false;
10211022
$alwaysTerminating = true;
1022-
$hasYield = false;
1023+
$hasYield = $condResult->hasYield();
10231024
foreach ($stmt->cases as $caseNode) {
10241025
if ($caseNode->cond !== null) {
10251026
$condExpr = new BinaryOp\Equal($stmt->cond, $caseNode->cond);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ public function yieldInIf(): \Generator
426426
}
427427
}
428428

429+
public function yieldInSwitch(): \Generator
430+
{
431+
switch (yield 1) {
432+
default:
433+
}
434+
}
435+
429436
}
430437

431438
class VoidUnion

0 commit comments

Comments
 (0)