Skip to content

Commit 8d619a6

Browse files
committed
Reapply the while loop fix again
1 parent de0a64c commit 8d619a6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,22 @@ private function processStmtNode(
12821282
} elseif ($stmt instanceof While_) {
12831283
$condResult = $this->processExprNode($stmt, $stmt->cond, $scope, static function (): void {
12841284
}, ExpressionContext::createDeep());
1285+
$beforeCondBooleanType = ($this->treatPhpDocTypesAsCertain ? $scope->getType($stmt->cond) : $scope->getNativeType($stmt->cond))->toBoolean();
1286+
$condScope = $condResult->getFalseyScope();
1287+
if (!$context->isTopLevel() && $beforeCondBooleanType->isFalse()->yes()) {
1288+
if (!$this->polluteScopeWithLoopInitialAssignments) {
1289+
$scope = $condScope->mergeWith($scope);
1290+
}
1291+
1292+
return new StatementResult(
1293+
$scope,
1294+
$condResult->hasYield(),
1295+
false,
1296+
[],
1297+
$condResult->getThrowPoints(),
1298+
$condResult->getImpurePoints(),
1299+
);
1300+
}
12851301
$bodyScope = $condResult->getTruthyScope();
12861302

12871303
if ($context->isTopLevel()) {
@@ -1328,7 +1344,6 @@ private function processStmtNode(
13281344
$finalScope = $finalScope->mergeWith($breakExitPoint->getScope());
13291345
}
13301346

1331-
$beforeCondBooleanType = ($this->treatPhpDocTypesAsCertain ? $scope->getType($stmt->cond) : $scope->getNativeType($stmt->cond))->toBoolean();
13321347
$isIterableAtLeastOnce = $beforeCondBooleanType->isTrue()->yes();
13331348
$nodeCallback(new BreaklessWhileLoopNode($stmt, $finalScopeResult->getExitPoints()), $bodyScopeMaybeRan);
13341349

@@ -1339,7 +1354,6 @@ private function processStmtNode(
13391354
} else {
13401355
$isAlwaysTerminating = false;
13411356
}
1342-
$condScope = $condResult->getFalseyScope();
13431357
if (!$isIterableAtLeastOnce) {
13441358
if (!$this->polluteScopeWithLoopInitialAssignments) {
13451359
$condScope = $condScope->mergeWith($scope);

0 commit comments

Comments
 (0)