Skip to content

Commit 707aa79

Browse files
committed
Fix missing detection of dead code in arrow functions
1 parent 252390f commit 707aa79

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
@@ -3206,7 +3206,7 @@ static function (): void {
32063206
return new ExpressionResult(
32073207
$result->getScope(),
32083208
$result->hasYield(),
3209-
$result->isAlwaysTerminating(),
3209+
false,
32103210
[],
32113211
[],
32123212
);
@@ -4818,7 +4818,7 @@ private function processArrowFunctionNode(
48184818
$nodeCallback(new InArrowFunctionNode($arrowFunctionType, $expr), $arrowFunctionScope);
48194819
$exprResult = $this->processExprNode($stmt, $expr->expr, $arrowFunctionScope, $nodeCallback, ExpressionContext::createTopLevel());
48204820

4821-
return new ExpressionResult($scope, false, false, $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
4821+
return new ExpressionResult($scope, false, $exprResult->isAlwaysTerminating(), $exprResult->getThrowPoints(), $exprResult->getImpurePoints());
48224822
}
48234823

48244824
/**
@@ -5246,6 +5246,7 @@ private function processArgs(
52465246
if ($callCallbackImmediately) {
52475247
$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()));
52485248
$impurePoints = array_merge($impurePoints, $arrowFunctionResult->getImpurePoints());
5249+
$isAlwaysTerminating = $isAlwaysTerminating || $arrowFunctionResult->isAlwaysTerminating();
52495250
}
52505251
} else {
52515252
$exprType = $scope->getType($arg->value);

tests/PHPStan/Analyser/ExpressionResultTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public static function dataIsAlwaysTerminating(): array
101101
'exit() ?? $x;',
102102
true,
103103
],
104+
[
105+
'call_user_func(fn() => exit());',
106+
true,
107+
],
104108
[
105109
'var_dump(1+exit());',
106110
true,

0 commit comments

Comments
 (0)