Skip to content

Commit 149e50c

Browse files
phpstan-botclaude
andcommitted
Add test for chained static call with never-returning argument
Add a test case where a static call with a never-returning argument is chained to a method call, testing the interaction between StaticCallHandler and MethodCallHandler isAlwaysTerminating propagation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6ab487a commit 149e50c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,15 @@ public function testBug14328(): void
380380
$this->analyse([__DIR__ . '/data/bug-14328.php'], [
381381
[
382382
'Unreachable statement - code above always terminates.',
383-
21,
383+
25,
384384
],
385385
[
386386
'Unreachable statement - code above always terminates.',
387-
27,
387+
31,
388+
],
389+
[
390+
'Unreachable statement - code above always terminates.',
391+
37,
388392
],
389393
]);
390394
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class Foo {
88
public function returnThis(mixed $value): self {
99
return $this;
1010
}
11+
12+
public static function staticReturnSelf(mixed $value): self {
13+
return new self();
14+
}
1115
}
1216

1317
class Bar {
@@ -26,3 +30,9 @@ function testStaticCall(): void {
2630
Bar::doSomething($callback());
2731
$b = 'this will never run';
2832
}
33+
34+
function testStaticCallChained(): void {
35+
$callback = fn (): never => throw new \Exception();
36+
$a = Foo::staticReturnSelf($callback())->returnThis('x');
37+
$b = 'this will never run either';
38+
}

0 commit comments

Comments
 (0)