Skip to content

Commit 6ab487a

Browse files
phpstan-botclaude
andcommitted
Add test for unreachable statement after static call with never-returning arg
Addresses review feedback from staabm: the StaticCallHandler fix was missing a test. Restructured the test data into separate functions so each scenario (method call chain vs static call) is independently tested. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 87a0047 commit 6ab487a

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,11 @@ public function testBug14328(): void
380380
$this->analyse([__DIR__ . '/data/bug-14328.php'], [
381381
[
382382
'Unreachable statement - code above always terminates.',
383-
16,
383+
21,
384+
],
385+
[
386+
'Unreachable statement - code above always terminates.',
387+
27,
384388
],
385389
]);
386390
}

tests/PHPStan/Rules/DeadCode/data/bug-14328.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44

55
namespace Bug14328;
66

7-
$callback = fn (): never => throw new \Exception();
8-
97
class Foo {
108
public function returnThis(mixed $value): self {
119
return $this;
1210
}
1311
}
1412

15-
$x = (new Foo())->returnThis($callback())->returnThis('x');
16-
$y = 'this will never run';
13+
class Bar {
14+
public static function doSomething(mixed $value): void {
15+
}
16+
}
17+
18+
function testMethodCall(): void {
19+
$callback = fn (): never => throw new \Exception();
20+
$x = (new Foo())->returnThis($callback())->returnThis('x');
21+
$y = 'this will never run';
22+
}
23+
24+
function testStaticCall(): void {
25+
$callback = fn (): never => throw new \Exception();
26+
Bar::doSomething($callback());
27+
$b = 'this will never run';
28+
}

0 commit comments

Comments
 (0)