Skip to content

Commit d136a9f

Browse files
committed
Do not mark __halt_compiler() unreachable
1 parent 998f817 commit d136a9f

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6064,7 +6064,7 @@ private function getFirstUnreachableNode(array $nodes, bool $earlyBinding): ?Nod
60646064
if ($node instanceof Node\Stmt\Nop) {
60656065
continue;
60666066
}
6067-
if ($earlyBinding && ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassLike)) {
6067+
if ($earlyBinding && ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassLike || $node instanceof Node\Stmt\HaltCompiler)) {
60686068
continue;
60696069
}
60706070
return $node;

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,10 @@ public function testBug8966(): void
218218
]);
219219
}
220220

221+
public function testBug11179(): void
222+
{
223+
$this->treatPhpDocTypesAsCertain = true;
224+
$this->analyse([__DIR__ . '/data/bug-11179.php'], []);
225+
}
226+
221227
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11179;
4+
5+
exit(0);
6+
7+
function foo(string $p): string
8+
{
9+
\PHPStan\dumpType($p);
10+
return "";
11+
}
12+
13+
__halt_compiler();
14+
foo

0 commit comments

Comments
 (0)