diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index c2ae0e2177..64e53c478e 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -1318,12 +1318,6 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu $impurePoints = array_merge($arrowFunctionImpurePoints, $arrowFunctionExprResult->getImpurePoints()); $usedVariables = []; } else { - $closureScope = $this->enterAnonymousFunctionWithoutReflection($node, $callableParameters); - $closureReturnStatements = []; - $closureYieldStatements = []; - $closureExecutionEnds = []; - $closureImpurePoints = []; - $invalidateExpressions = []; if (self::$resolveClosureTypeDepth >= 2) { return new ClosureType( $parameters, @@ -1333,6 +1327,14 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu } self::$resolveClosureTypeDepth++; + + $closureScope = $this->enterAnonymousFunctionWithoutReflection($node, $callableParameters); + $closureReturnStatements = []; + $closureYieldStatements = []; + $closureExecutionEnds = []; + $closureImpurePoints = []; + $invalidateExpressions = []; + try { $closureStatementResult = $this->nodeScopeResolver->processStmtNodes($node, $node->stmts, $closureScope, static function (Node $node, Scope $scope) use ($closureScope, &$closureReturnStatements, &$closureYieldStatements, &$closureExecutionEnds, &$closureImpurePoints, &$invalidateExpressions): void { if ($scope->getAnonymousFunctionReflection() !== $closureScope->getAnonymousFunctionReflection()) {