Skip to content

Commit acf9bb9

Browse files
committed
Fix missing detection of dead code in arrow functions
1 parent 9dbff97 commit acf9bb9

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
/**
@@ -5232,6 +5232,7 @@ private function processArgs(
52325232
if ($callCallbackImmediately) {
52335233
$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()));
52345234
$impurePoints = array_merge($impurePoints, $arrowFunctionResult->getImpurePoints());
5235+
$isAlwaysTerminating = $isAlwaysTerminating || $arrowFunctionResult->isAlwaysTerminating();
52355236
}
52365237
} else {
52375238
$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)