diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 001c8b5b36..126932e2f6 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -4442,6 +4442,14 @@ private function getNextUnreachableStatements(array $nodes, bool $earlyBinding): if ($node instanceof Node\Stmt\Nop || $node instanceof Node\Stmt\InlineHTML) { continue; } + if ( + $node instanceof Node\Stmt\Expression + && $node->expr instanceof Expr\Yield_ + && $node->expr->key === null + && $node->expr->value === null + ) { + continue; + } if (!$node instanceof Node\Stmt) { continue; } diff --git a/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php index d191658d0e..b3ce494b6f 100644 --- a/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php @@ -397,6 +397,12 @@ public function testBug14328(): void ]); } + public function testBug11181(): void + { + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-11181.php'], []); + } + public function testBug14369(): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-11181.php b/tests/PHPStan/Rules/DeadCode/data/bug-11181.php new file mode 100644 index 0000000000..94c69ceb94 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-11181.php @@ -0,0 +1,21 @@ +