Skip to content

Commit 8bccc4f

Browse files
committed
Fix missing detection of dead code in arrow functions
1 parent 1f150cc commit 8bccc4f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,7 +3192,7 @@ static function (): void {
31923192
return new ExpressionResult(
31933193
$result->getScope(),
31943194
$result->hasYield(),
3195-
$result->isAlwaysTerminating(),
3195+
false,
31963196
[],
31973197
[],
31983198
);
@@ -4804,7 +4804,7 @@ private function processArrowFunctionNode(
48044804
$nodeCallback(new InArrowFunctionNode($arrowFunctionType, $expr), $arrowFunctionScope);
48054805
$exprResult = $this->processExprNode($stmt, $expr->expr, $arrowFunctionScope, $nodeCallback, ExpressionContext::createTopLevel());
48064806

4807-
return new ExpressionResult($scope, false, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
4807+
return new ExpressionResult($scope, false, $exprResult->isAlwaysTerminating(), $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
48084808
}
48094809

48104810
/**
@@ -5226,6 +5226,7 @@ private function processArgs(
52265226
if ($callCallbackImmediately) {
52275227
$throwPoints = array_merge($throwPoints, array_map(static fn (ThrowPoint $throwPoint) => $throwPoint->isExplicit() ? ThrowPoint::createExplicit($scope, $throwPoint->getType(), $arg->value, $throwPoint->canContainAnyThrowable()) : ThrowPoint::createImplicit($scope, $arg->value), $arrowFunctionResult->getThrowPoints()));
52285228
$impurePoints = array_merge($impurePoints, $arrowFunctionResult->getImpurePoints());
5229+
$isAlwaysTerminating = $isAlwaysTerminating || $arrowFunctionResult->isAlwaysTerminating();
52295230
}
52305231
} else {
52315232
$exprType = $scope->getType($arg->value);

tests/PHPStan/Analyser/ExpressionResultTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public static function dataIsAlwaysTerminating(): array
9999
'exit() ?? $x;',
100100
true,
101101
],
102+
[
103+
'call_user_func(fn() => exit());',
104+
true,
105+
],
102106
[
103107
'var_dump(1+exit());',
104108
true,

0 commit comments

Comments
 (0)