Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-11181.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Bug11181;

function foo(): \Iterator
{
return;
yield;
}

function bar(): \Generator
{
return;
yield;
}

function baz(): iterable
{
return;
yield;
}
Loading