@@ -132,6 +132,9 @@ final class InitializerExprTypeResolver
132132 /** @var array<string, true> */
133133 private array $ currentlyResolvingClassConstant = [];
134134
135+ /** @var array<string, Type> */
136+ private array $ classConstantValueTypeCache = [];
137+
135138 public function __construct (
136139 private ConstantResolver $ constantResolver ,
137140 private ReflectionProviderProvider $ reflectionProviderProvider ,
@@ -2530,6 +2533,11 @@ function (Type $type, callable $traverse): Type {
25302533 continue ;
25312534 }
25322535
2536+ if (!$ isObject && array_key_exists ($ resolvingName , $ this ->classConstantValueTypeCache )) {
2537+ $ types [] = $ this ->classConstantValueTypeCache [$ resolvingName ];
2538+ continue ;
2539+ }
2540+
25332541 $ this ->currentlyResolvingClassConstant [$ resolvingName ] = true ;
25342542
25352543 if (!$ isObject ) {
@@ -2544,13 +2552,15 @@ function (Type $type, callable $traverse): Type {
25442552 if ($ reflectionConstant ->getType () !== null ) {
25452553 $ nativeType = TypehintHelper::decideTypeFromReflection ($ reflectionConstant ->getType (), selfClass: $ constantClassReflection );
25462554 }
2547- $ types [] = $ this ->constantResolver ->resolveClassConstantType (
2555+ $ resolvedType = $ this ->constantResolver ->resolveClassConstantType (
25482556 $ constantClassReflection ->getName (),
25492557 $ constantName ,
25502558 $ constantType ,
25512559 $ nativeType ,
25522560 $ constantClassReflection ->getConstantPhpDocType ($ constantName ),
25532561 );
2562+ $ this ->classConstantValueTypeCache [$ resolvingName ] = $ resolvedType ;
2563+ $ types [] = $ resolvedType ;
25542564 unset($ this ->currentlyResolvingClassConstant [$ resolvingName ]);
25552565 continue ;
25562566 }
0 commit comments