@@ -180,6 +180,8 @@ class MutatingScope implements Scope
180
180
181
181
private ?self $ scopeWithPromotedNativeTypes = null ;
182
182
183
+ private static int $ resolveClosureTypeDepth = 0 ;
184
+
183
185
/**
184
186
* @param array<string, ExpressionTypeHolder> $expressionTypes
185
187
* @param array<string, ConditionalExpressionHolder[]> $conditionalExpressions
@@ -1322,6 +1324,16 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1322
1324
$ closureExecutionEnds = [];
1323
1325
$ closureImpurePoints = [];
1324
1326
$ invalidateExpressions = [];
1327
+ if (self ::$ resolveClosureTypeDepth >= 2 ) {
1328
+ return new ClosureType (
1329
+ $ parameters ,
1330
+ $ this ->getFunctionType ($ node ->returnType , false , false ),
1331
+ $ isVariadic ,
1332
+ );
1333
+ }
1334
+
1335
+ self ::$ resolveClosureTypeDepth ++;
1336
+ try {
1325
1337
$ closureStatementResult = $ this ->nodeScopeResolver ->processStmtNodes ($ node , $ node ->stmts , $ closureScope , static function (Node $ node , Scope $ scope ) use ($ closureScope , &$ closureReturnStatements , &$ closureYieldStatements , &$ closureExecutionEnds , &$ closureImpurePoints , &$ invalidateExpressions ): void {
1326
1338
if ($ scope ->getAnonymousFunctionReflection () !== $ closureScope ->getAnonymousFunctionReflection ()) {
1327
1339
return ;
@@ -1372,6 +1384,9 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1372
1384
1373
1385
$ closureYieldStatements [] = [$ node , $ scope ];
1374
1386
}, StatementContext::createTopLevel ());
1387
+ } finally {
1388
+ self ::$ resolveClosureTypeDepth --;
1389
+ }
1375
1390
1376
1391
$ throwPoints = $ closureStatementResult ->getThrowPoints ();
1377
1392
$ impurePoints = array_merge ($ closureImpurePoints , $ closureStatementResult ->getImpurePoints ());
0 commit comments