Skip to content

Commit

Permalink
disable creating conditional expression when entering foreach if poll…
Browse files Browse the repository at this point in the history
…uteScopeWithAlwaysIterableForeach: false
  • Loading branch information
rajyan committed Dec 7, 2022
1 parent 8e03374 commit 63ed3a5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,11 @@ private function processStmtNode(
$inForeachScope = $this->processVarAnnotation($scope, [$stmt->expr->name], $stmt);
}
$nodeCallback(new InForeachNode($stmt), $inForeachScope);
$bodyScope = $this->enterForeach($scope->filterByTruthyValue($arrayComparisonExpr), $stmt);
$bodyScope = $this->polluteScopeWithAlwaysIterableForeach ? $this->enterForeach($scope->filterByTruthyValue($arrayComparisonExpr), $stmt) : $this->enterForeach($scope, $stmt);
$count = 0;
do {
$prevScope = $bodyScope;
$bodyScope = $bodyScope->mergeWith($scope->filterByTruthyValue($arrayComparisonExpr));
$bodyScope = $bodyScope->mergeWith($this->polluteScopeWithAlwaysIterableForeach ? $scope->filterByTruthyValue($arrayComparisonExpr) : $scope);
$bodyScope = $this->enterForeach($bodyScope, $stmt);
$bodyScopeResult = $this->processStmtNodes($stmt, $stmt->stmts, $bodyScope, static function (): void {
})->filterOutLoopExitPoints();
Expand All @@ -841,7 +841,7 @@ private function processStmtNode(
$count++;
} while (!$alwaysTerminating && $count < self::LOOP_SCOPE_ITERATIONS);

$bodyScope = $bodyScope->mergeWith($scope->filterByTruthyValue($arrayComparisonExpr));
$bodyScope = $bodyScope->mergeWith($this->polluteScopeWithAlwaysIterableForeach ? $scope->filterByTruthyValue($arrayComparisonExpr) : $scope);
$bodyScope = $this->enterForeach($bodyScope, $stmt);
$finalScopeResult = $this->processStmtNodes($stmt, $stmt->stmts, $bodyScope, $nodeCallback)->filterOutLoopExitPoints();
$finalScope = $finalScopeResult->getScope();
Expand Down

0 comments on commit 63ed3a5

Please sign in to comment.