@@ -5899,28 +5899,31 @@ private function exactInstantiation(New_ $node, string $className): ?Type
58995899
59005900 $ assignedToProperty = $ node ->getAttribute (NewAssignedToPropertyVisitor::ATTRIBUTE_NAME );
59015901 if ($ assignedToProperty !== null ) {
5902- $ constructorVariant = $ constructorMethod ->getOnlyVariant ();
5903- $ classTemplateTypes = $ classReflection ->getTemplateTypeMap ()->getTypes ();
5904- $ originalClassTemplateTypes = $ classTemplateTypes ;
5905- foreach ($ constructorVariant ->getParameters () as $ parameter ) {
5906- TypeTraverser::map ($ parameter ->getType (), static function (Type $ type , callable $ traverse ) use (&$ classTemplateTypes ): Type {
5907- if ($ type instanceof TemplateType && array_key_exists ($ type ->getName (), $ classTemplateTypes )) {
5908- $ classTemplateType = $ classTemplateTypes [$ type ->getName ()];
5909- if ($ classTemplateType instanceof TemplateType && $ classTemplateType ->getScope ()->equals ($ type ->getScope ())) {
5910- unset($ classTemplateTypes [$ type ->getName ()]);
5902+ $ constructorVariants = $ constructorMethod ->getVariants ();
5903+ if (count ($ constructorVariants ) === 1 ) {
5904+ $ constructorVariant = $ constructorVariants [0 ];
5905+ $ classTemplateTypes = $ classReflection ->getTemplateTypeMap ()->getTypes ();
5906+ $ originalClassTemplateTypes = $ classTemplateTypes ;
5907+ foreach ($ constructorVariant ->getParameters () as $ parameter ) {
5908+ TypeTraverser::map ($ parameter ->getType (), static function (Type $ type , callable $ traverse ) use (&$ classTemplateTypes ): Type {
5909+ if ($ type instanceof TemplateType && array_key_exists ($ type ->getName (), $ classTemplateTypes )) {
5910+ $ classTemplateType = $ classTemplateTypes [$ type ->getName ()];
5911+ if ($ classTemplateType instanceof TemplateType && $ classTemplateType ->getScope ()->equals ($ type ->getScope ())) {
5912+ unset($ classTemplateTypes [$ type ->getName ()]);
5913+ }
5914+ return $ type ;
59115915 }
5912- return $ type ;
5913- }
59145916
5915- return $ traverse ($ type );
5916- });
5917- }
5917+ return $ traverse ($ type );
5918+ });
5919+ }
59185920
5919- if (count ($ classTemplateTypes ) === count ($ originalClassTemplateTypes )) {
5920- $ propertyType = TypeCombinator::removeNull ($ this ->getType ($ assignedToProperty ));
5921- $ nonFinalObjectType = $ isStatic ? new StaticType ($ nonFinalClassReflection ) : new ObjectType ($ resolvedClassName , classReflection: $ nonFinalClassReflection );
5922- if ($ nonFinalObjectType ->isSuperTypeOf ($ propertyType )->yes ()) {
5923- return $ propertyType ;
5921+ if (count ($ classTemplateTypes ) === count ($ originalClassTemplateTypes )) {
5922+ $ propertyType = TypeCombinator::removeNull ($ this ->getType ($ assignedToProperty ));
5923+ $ nonFinalObjectType = $ isStatic ? new StaticType ($ nonFinalClassReflection ) : new ObjectType ($ resolvedClassName , classReflection: $ nonFinalClassReflection );
5924+ if ($ nonFinalObjectType ->isSuperTypeOf ($ propertyType )->yes ()) {
5925+ return $ propertyType ;
5926+ }
59245927 }
59255928 }
59265929 }
0 commit comments