Skip to content

Commit 9f33665

Browse files
committed
de-duplicate fix
1 parent f2bf92b commit 9f33665

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,27 +4293,6 @@ private function processClosureNode(
42934293
return new ProcessClosureResult($scope, $statementResult->getThrowPoints(), $statementResult->getImpurePoints(), $invalidateExpressions);
42944294
}
42954295

4296-
if ($expr->getAttribute(ImmediatelyInvokedClosureVisitor::ATTRIBUTE_NAME) === true) {
4297-
$intermediaryClosureScopeResult = $this->processStmtNodes($expr, $expr->stmts, $closureScope, static function (): void {
4298-
}, StatementContext::createTopLevel());
4299-
$intermediaryClosureScope = $intermediaryClosureScopeResult->getScope();
4300-
foreach ($intermediaryClosureScopeResult->getExitPoints() as $exitPoint) {
4301-
$intermediaryClosureScope = $intermediaryClosureScope->mergeWith($exitPoint->getScope());
4302-
}
4303-
4304-
$statementResult = $this->processStmtNodes($expr, $expr->stmts, $closureScope, $closureStmtsCallback, StatementContext::createTopLevel());
4305-
$nodeCallback(new ClosureReturnStatementsNode(
4306-
$expr,
4307-
$gatheredReturnStatements,
4308-
$gatheredYieldStatements,
4309-
$statementResult,
4310-
$executionEnds,
4311-
array_merge($statementResult->getImpurePoints(), $closureImpurePoints),
4312-
), $closureScope);
4313-
4314-
return new ProcessClosureResult($scope->processClosureScope($intermediaryClosureScope, null, $byRefUses), $statementResult->getThrowPoints(), $statementResult->getImpurePoints(), $invalidateExpressions);
4315-
}
4316-
43174296
$count = 0;
43184297
do {
43194298
$prevScope = $closureScope;
@@ -4324,8 +4303,15 @@ private function processClosureNode(
43244303
foreach ($intermediaryClosureScopeResult->getExitPoints() as $exitPoint) {
43254304
$intermediaryClosureScope = $intermediaryClosureScope->mergeWith($exitPoint->getScope());
43264305
}
4306+
4307+
if ($expr->getAttribute(ImmediatelyInvokedClosureVisitor::ATTRIBUTE_NAME) === true) {
4308+
$closureResultScope = $intermediaryClosureScope;
4309+
break;
4310+
}
4311+
43274312
$closureScope = $scope->enterAnonymousFunction($expr, $callableParameters);
43284313
$closureScope = $closureScope->processClosureScope($intermediaryClosureScope, $prevScope, $byRefUses);
4314+
43294315
if ($closureScope->equals($prevScope)) {
43304316
break;
43314317
}
@@ -4335,6 +4321,10 @@ private function processClosureNode(
43354321
$count++;
43364322
} while ($count < self::LOOP_SCOPE_ITERATIONS);
43374323

4324+
if (!isset($closureResultScope)) {
4325+
$closureResultScope = $closureScope;
4326+
}
4327+
43384328
$statementResult = $this->processStmtNodes($expr, $expr->stmts, $closureScope, $closureStmtsCallback, StatementContext::createTopLevel());
43394329
$nodeCallback(new ClosureReturnStatementsNode(
43404330
$expr,
@@ -4345,7 +4335,7 @@ private function processClosureNode(
43454335
array_merge($statementResult->getImpurePoints(), $closureImpurePoints),
43464336
), $closureScope);
43474337

4348-
return new ProcessClosureResult($scope->processClosureScope($closureScope, null, $byRefUses), $statementResult->getThrowPoints(), $statementResult->getImpurePoints(), $invalidateExpressions);
4338+
return new ProcessClosureResult($scope->processClosureScope($closureResultScope, null, $byRefUses), $statementResult->getThrowPoints(), $statementResult->getImpurePoints(), $invalidateExpressions);
43494339
}
43504340

43514341
/**

0 commit comments

Comments
 (0)