Skip to content

Commit e7d00d1

Browse files
committed
fix arrays
1 parent 0b642df commit e7d00d1

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
@@ -2935,7 +2935,7 @@ static function (): void {
29352935
$exprResult->getThrowPoints(),
29362936
$exprResult->getImpurePoints(),
29372937
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
2938-
static fn (): MutatingScope => $scope->filterByFalseyValue($expr)
2938+
static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
29392939
);
29402940
} elseif ($expr instanceof StaticCall) {
29412941
$hasYield = false;
@@ -3247,13 +3247,15 @@ static function (): void {
32473247
$hasYield = $hasYield || $keyResult->hasYield();
32483248
$throwPoints = array_merge($throwPoints, $keyResult->getThrowPoints());
32493249
$impurePoints = array_merge($impurePoints, $keyResult->getImpurePoints());
3250+
$isAlwaysTerminating = $isAlwaysTerminating || $keyResult->isAlwaysTerminating();
32503251
$scope = $keyResult->getScope();
32513252
}
32523253

32533254
$valueResult = $this->processExprNode($stmt, $arrayItem->value, $scope, $nodeCallback, $context->enterDeep());
32543255
$hasYield = $hasYield || $valueResult->hasYield();
32553256
$throwPoints = array_merge($throwPoints, $valueResult->getThrowPoints());
32563257
$impurePoints = array_merge($impurePoints, $valueResult->getImpurePoints());
3258+
$isAlwaysTerminating = $isAlwaysTerminating || $valueResult->isAlwaysTerminating();
32573259
$scope = $valueResult->getScope();
32583260
}
32593261
$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
@@ -285,6 +285,10 @@ public function testBug13232a(): void
285285
'Unreachable statement - code above always terminates.',
286286
32,
287287
],
288+
[
289+
'Unreachable statement - code above always terminates.',
290+
40,
291+
],
288292
]);
289293
}
290294

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)