@@ -838,31 +838,34 @@ private static function processArrayTypes(array $arrayTypes): array
838838 if (count ($ reducedArrayTypes ) === 1 ) {
839839 return [self ::intersect ($ reducedArrayTypes [0 ], ...$ accessoryTypes )];
840840 }
841- $ scopes = [];
842- $ useTemplateArray = true ;
841+
842+ $ templateArrayType = null ;
843843 foreach ($ arrayTypes as $ arrayType ) {
844844 if (!$ arrayType instanceof TemplateArrayType) {
845- $ useTemplateArray = false ;
845+ $ templateArrayType = null ;
846846 break ;
847847 }
848848
849- $ scopes [$ arrayType ->getScope ()->describe ()] = $ arrayType ;
849+ if ($ templateArrayType !== null ) {
850+ continue ;
851+ }
852+
853+ $ templateArrayType = $ arrayType ;
850854 }
851855
852856 $ arrayType = new ArrayType (
853857 self ::union (...$ keyTypesForGeneralArray ),
854858 self ::union (...self ::optimizeConstantArrays ($ valueTypesForGeneralArray )),
855859 );
856860
857- if ($ useTemplateArray && count ($ scopes ) === 1 ) {
858- $ templateArray = array_values ($ scopes )[0 ];
861+ if ($ templateArrayType !== null ) {
859862 $ arrayType = new TemplateArrayType (
860- $ templateArray ->getScope (),
861- $ templateArray ->getStrategy (),
862- $ templateArray ->getVariance (),
863- $ templateArray ->getName (),
863+ $ templateArrayType ->getScope (),
864+ $ templateArrayType ->getStrategy (),
865+ $ templateArrayType ->getVariance (),
866+ $ templateArrayType ->getName (),
864867 $ arrayType ,
865- $ templateArray ->getDefault (),
868+ $ templateArrayType ->getDefault (),
866869 );
867870 }
868871
@@ -1106,12 +1109,12 @@ private static function reduceArrays(array $constantArrays, bool $preserveTagged
11061109
11071110 public static function intersect (Type ...$ types ): Type
11081111 {
1109- $ types = array_values ($ types );
1110-
11111112 $ typesCount = count ($ types );
11121113 if ($ typesCount === 0 ) {
11131114 return new NeverType ();
11141115 }
1116+
1117+ $ types = array_values ($ types );
11151118 if ($ typesCount === 1 ) {
11161119 return $ types [0 ];
11171120 }
0 commit comments