Skip to content

Commit e619c1a

Browse files
committed
fix arrays
1 parent f868b58 commit e619c1a

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,7 @@ static function (): void {
29322932
$exprResult->getThrowPoints(),
29332933
$exprResult->getImpurePoints(),
29342934
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
2935-
static fn (): MutatingScope => $scope->filterByFalseyValue($expr)
2935+
static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
29362936
);
29372937
} elseif ($expr instanceof StaticCall) {
29382938
$hasYield = false;
@@ -3244,13 +3244,15 @@ static function (): void {
32443244
$hasYield = $hasYield || $keyResult->hasYield();
32453245
$throwPoints = array_merge($throwPoints, $keyResult->getThrowPoints());
32463246
$impurePoints = array_merge($impurePoints, $keyResult->getImpurePoints());
3247+
$isAlwaysTerminating = $isAlwaysTerminating || $keyResult->isAlwaysTerminating();
32473248
$scope = $keyResult->getScope();
32483249
}
32493250

32503251
$valueResult = $this->processExprNode($stmt, $arrayItem->value, $scope, $nodeCallback, $context->enterDeep());
32513252
$hasYield = $hasYield || $valueResult->hasYield();
32523253
$throwPoints = array_merge($throwPoints, $valueResult->getThrowPoints());
32533254
$impurePoints = array_merge($impurePoints, $valueResult->getImpurePoints());
3255+
$isAlwaysTerminating = $isAlwaysTerminating || $valueResult->isAlwaysTerminating();
32543256
$scope = $valueResult->getScope();
32553257
}
32563258
$nodeCallback(new LiteralArrayNode($expr, $itemNodes), $scope);

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ public function testBug13232a(): void
274274
'Unreachable statement - code above always terminates.',
275275
32,
276276
],
277+
[
278+
'Unreachable statement - code above always terminates.',
279+
40,
280+
],
277281
]);
278282
}
279283

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public function sayHe(): void
3232
echo 'this will never happen';
3333
}
3434

35+
public function sayHuu(): void
36+
{
37+
$x = [
38+
$this->neverReturnsMethod()
39+
];
40+
echo 'this will never happen';
41+
}
3542

3643
function neverReturnsMethod(): never {
3744
exit();

0 commit comments

Comments
 (0)