@@ -50,31 +50,35 @@ public function getReturnValueType(Type $arrayType, Type $columnType, Scope $sco
5050 return [$ returnValueType , $ iterableAtLeastOnce ];
5151 }
5252
53- public function handleAnyArray (Type $ arrayType, Type $ columnType , ?Type $ indexType , Scope $ scope ): Type
53+ public function getReturnIndexType (Type $ arrayType , ?Type $ indexType , Scope $ scope ): Type
5454 {
55- [$ returnValueType , $ iterableAtLeastOnce ] = $ this ->getReturnValueType ($ arrayType , $ columnType , $ scope );
56- if ($ returnValueType instanceof NeverType) {
57- return new ConstantArrayType ([], []);
58- }
59-
6055 if ($ indexType !== null ) {
6156 $ iterableValueType = $ arrayType ->getIterableValueType ();
6257
6358 $ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , false );
6459 if ($ type !== null ) {
65- $ returnKeyType = $ type ;
66- } else {
67- $ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , true );
68- if ($ type !== null ) {
69- $ returnKeyType = TypeCombinator::union ($ type , new IntegerType ());
70- } else {
71- $ returnKeyType = new IntegerType ();
72- }
60+ return $ type ;
7361 }
74- } else {
75- $ returnKeyType = new IntegerType ();
62+
63+ $ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , true );
64+ if ($ type !== null ) {
65+ return TypeCombinator::union ($ type , new IntegerType ());
66+ }
67+
68+ return new IntegerType ();
69+ }
70+
71+ return new IntegerType ();
72+ }
73+
74+ public function handleAnyArray (Type $ arrayType , Type $ columnType , ?Type $ indexType , Scope $ scope ): Type
75+ {
76+ [$ returnValueType , $ iterableAtLeastOnce ] = $ this ->getReturnValueType ($ arrayType , $ columnType , $ scope );
77+ if ($ returnValueType instanceof NeverType) {
78+ return new ConstantArrayType ([], []);
7679 }
7780
81+ $ returnKeyType = $ this ->getReturnIndexType ($ arrayType , $ indexType , $ scope );
7882 $ returnType = new ArrayType ($ this ->castToArrayKeyType ($ returnKeyType ), $ returnValueType );
7983
8084 if ($ iterableAtLeastOnce ->yes ()) {
0 commit comments