@@ -2020,7 +2020,7 @@ public function restoreThis(self $restoreThisScope): self
20202020 $ expressionTypes ,
20212021 $ nativeExpressionTypes ,
20222022 $ this ->conditionalExpressions ,
2023- $ this ->inClosureBindScopeClasses ,
2023+ $ restoreThisScope ->inClosureBindScopeClasses ,
20242024 $ this ->anonymousFunctionReflection ,
20252025 $ this ->inFirstLevelStatement ,
20262026 [],
@@ -2059,6 +2059,31 @@ public function isInClosureBind(): bool
20592059 return $ this ->inClosureBindScopeClasses !== [];
20602060 }
20612061
2062+ /**
2063+ * @param list<non-empty-string> $scopeClasses
2064+ */
2065+ public function withClosureBindScopeClasses (array $ scopeClasses ): self
2066+ {
2067+ return $ this ->scopeFactory ->create (
2068+ $ this ->context ,
2069+ $ this ->isDeclareStrictTypes (),
2070+ $ this ->getFunction (),
2071+ $ this ->getNamespace (),
2072+ $ this ->expressionTypes ,
2073+ $ this ->nativeExpressionTypes ,
2074+ $ this ->conditionalExpressions ,
2075+ $ scopeClasses ,
2076+ $ this ->anonymousFunctionReflection ,
2077+ $ this ->isInFirstLevelStatement (),
2078+ $ this ->currentlyAssignedExpressions ,
2079+ $ this ->currentlyAllowedUndefinedExpressions ,
2080+ $ this ->inFunctionCallsStack ,
2081+ $ this ->afterExtractCall ,
2082+ $ this ->parentScope ,
2083+ $ this ->nativeTypesPromoted ,
2084+ );
2085+ }
2086+
20622087 /**
20632088 * @api
20642089 * @param ParameterReflection[]|null $callableParameters
@@ -2397,6 +2422,23 @@ public function getFunctionType($type, bool $isNullable, bool $isVariadic): Type
23972422 false ,
23982423 )), new AccessoryArrayListType ()]);
23992424 }
2425+ if (
2426+ $ type instanceof Name
2427+ && $ this ->inClosureBindScopeClasses !== []
2428+ && $ this ->inClosureBindScopeClasses !== ['static ' ]
2429+ && in_array ($ type ->toLowerString (), ['static ' , 'self ' , 'parent ' ], true )
2430+ && $ this ->reflectionProvider ->hasClass ($ this ->inClosureBindScopeClasses [0 ])
2431+ ) {
2432+ return $ this ->initializerExprTypeResolver ->getFunctionType (
2433+ $ type ,
2434+ $ isNullable ,
2435+ false ,
2436+ InitializerExprContext ::fromClassReflection (
2437+ $ this ->reflectionProvider ->getClass ($ this ->inClosureBindScopeClasses [0 ]),
2438+ ),
2439+ );
2440+ }
2441+
24002442 return $ this ->initializerExprTypeResolver ->getFunctionType ($ type , $ isNullable , false , InitializerExprContext ::fromScope ($ this ));
24012443 }
24022444
0 commit comments