Skip to content

Commit 3ba48c9

Browse files
committed
fix callables
1 parent 6e9a443 commit 3ba48c9

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5177,6 +5177,8 @@ private function processArgs(
51775177
}
51785178
$throwPoints = array_merge($throwPoints, $callableThrowPoints);
51795179
$impurePoints = array_merge($impurePoints, array_map(static fn (SimpleImpurePoint $impurePoint) => new ImpurePoint($scope, $arg->value, $impurePoint->getIdentifier(), $impurePoint->getDescription(), $impurePoint->isCertain()), $acceptors[0]->getImpurePoints()));
5180+
$returnType = $acceptors[0]->getReturnType();
5181+
$isAlwaysTerminating = $isAlwaysTerminating || ($returnType instanceof NeverType && $returnType->isExplicit());
51805182
}
51815183
}
51825184
}

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ public function testBug13232a(): void
258258
'Unreachable statement - code above always terminates.',
259259
23,
260260
],
261+
[
262+
'Unreachable statement - code above always terminates.',
263+
32,
264+
],
261265
]);
262266
}
263267

tests/PHPStan/Rules/DeadCode/data/bug-13232a.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public function sayHo(): void
2323
echo 'this will never happen';
2424
}
2525

26+
public function sayHe(): void
27+
{
28+
$callable = function (): never {
29+
exit();
30+
};
31+
echo sprintf("Hello, %s no way", $callable);
32+
echo 'this will never happen';
33+
}
34+
35+
2636
function neverReturnsMethod(): never {
2737
exit();
2838
}

0 commit comments

Comments
 (0)