Skip to content

Commit 1cc37c6

Browse files
committed
For loop fix
1 parent a10c133 commit 1cc37c6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,25 @@ private function processStmtNode(
14941494
$bodyScope = $condResult->getTruthyScope();
14951495
}
14961496

1497+
if (!$context->isTopLevel() && $isIterableAtLeastOnce->no()) {
1498+
if (!isset($condResult)) {
1499+
throw new ShouldNotHappenException();
1500+
}
1501+
if ($this->polluteScopeWithLoopInitialAssignments) {
1502+
$finalScope = $condResult->getFalseyScope()->mergeWith($initScope);
1503+
} else {
1504+
$finalScope = $condResult->getFalseyScope()->mergeWith($scope);
1505+
}
1506+
return new StatementResult(
1507+
$finalScope,
1508+
$hasYield,
1509+
false,
1510+
[],
1511+
$throwPoints,
1512+
$impurePoints,
1513+
);
1514+
}
1515+
14971516
if ($context->isTopLevel()) {
14981517
$count = 0;
14991518
do {

0 commit comments

Comments
 (0)