Skip to content

Commit 33391ca

Browse files
committed
fix arrays
1 parent 2130cf9 commit 33391ca

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
@@ -2933,7 +2933,7 @@ static function (): void {
29332933
$exprResult->getThrowPoints(),
29342934
$exprResult->getImpurePoints(),
29352935
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
2936-
static fn (): MutatingScope => $scope->filterByFalseyValue($expr)
2936+
static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
29372937
);
29382938
} elseif ($expr instanceof StaticCall) {
29392939
$hasYield = false;
@@ -3245,13 +3245,15 @@ static function (): void {
32453245
$hasYield = $hasYield || $keyResult->hasYield();
32463246
$throwPoints = array_merge($throwPoints, $keyResult->getThrowPoints());
32473247
$impurePoints = array_merge($impurePoints, $keyResult->getImpurePoints());
3248+
$isAlwaysTerminating = $isAlwaysTerminating || $keyResult->isAlwaysTerminating();
32483249
$scope = $keyResult->getScope();
32493250
}
32503251

32513252
$valueResult = $this->processExprNode($stmt, $arrayItem->value, $scope, $nodeCallback, $context->enterDeep());
32523253
$hasYield = $hasYield || $valueResult->hasYield();
32533254
$throwPoints = array_merge($throwPoints, $valueResult->getThrowPoints());
32543255
$impurePoints = array_merge($impurePoints, $valueResult->getImpurePoints());
3256+
$isAlwaysTerminating = $isAlwaysTerminating || $valueResult->isAlwaysTerminating();
32553257
$scope = $valueResult->getScope();
32563258
}
32573259
$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)