@@ -66,6 +66,9 @@ final class FileTypeMapper
6666 /** @var array<string, true> */
6767 private array $ inProcess = [];
6868
69+ /** @var array<string, NameScope> */
70+ private array $ inProcessNameScopes = [];
71+
6972 /** @var array<string, ResolvedPhpDocBlock> */
7073 private array $ resolvedPhpDocBlockCache = [];
7174
@@ -200,6 +203,9 @@ public function getNameScope(
200203 {
201204 $ nameScopeKey = $ this ->getNameScopeKey ($ fileName , $ className , $ traitName , $ functionName );
202205 if (isset ($ this ->inProcess [$ nameScopeKey ])) {
206+ if (isset ($ this ->inProcessNameScopes [$ nameScopeKey ])) {
207+ return $ this ->inProcessNameScopes [$ nameScopeKey ];
208+ }
203209 throw new NameScopeAlreadyBeingCreatedException ();
204210 }
205211
@@ -288,6 +294,8 @@ public function getNameScope(
288294 continue ;
289295 }
290296
297+ $ this ->inProcessNameScopes [$ nameScopeKey ] = $ nameScope ;
298+
291299 $ templateTags = $ this ->phpDocNodeResolver ->resolveTemplateTags ($ parent ->getTemplatePhpDocNodes (), $ nameScope );
292300 $ templateTypeMap = new TemplateTypeMap (array_map (static fn (TemplateTag $ tag ): Type => TemplateTypeFactory::fromTemplateTag ($ templateTypeScope , $ tag ), $ templateTags ));
293301 $ nameScope = $ nameScope ->withTemplateTypeMap ($ templateTypeMap , $ templateTags );
@@ -319,6 +327,7 @@ public function getNameScope(
319327 );
320328 } finally {
321329 unset($ this ->inProcess [$ nameScopeKey ]);
330+ unset($ this ->inProcessNameScopes [$ nameScopeKey ]);
322331 }
323332 }
324333
0 commit comments