@@ -50,32 +50,33 @@ 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-
57- if ($ returnValueType instanceof NeverType) {
58- return new ConstantArrayType ([], []);
59- }
60-
6155 if ($ indexType !== null ) {
6256 $ iterableValueType = $ arrayType ->getIterableValueType ();
6357
6458 $ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , false );
6559 if ($ type !== null ) {
66- $ returnKeyType = $ type ;
67- } else {
68- $ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , true );
69- if ($ type !== null ) {
70- $ returnKeyType = TypeCombinator::union ($ type , new IntegerType ());
71- } else {
72- $ returnKeyType = new IntegerType ();
73- }
60+ return $ type ;
7461 }
75- } else {
76- $ 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+
69+ return new IntegerType ();
70+ }
71+
72+ public function handleAnyArray (Type $ arrayType , Type $ columnType , ?Type $ indexType , Scope $ scope ): Type
73+ {
74+ [$ returnValueType , $ iterableAtLeastOnce ] = $ this ->getReturnValueType ($ arrayType , $ columnType , $ scope );
75+ if ($ returnValueType instanceof NeverType) {
76+ return new ConstantArrayType ([], []);
7777 }
7878
79+ $ returnKeyType = $ this ->getReturnIndexType ($ arrayType , $ indexType , $ scope );
7980 $ returnType = new ArrayType ($ this ->castToArrayKeyType ($ returnKeyType ), $ returnValueType );
8081
8182 if ($ iterableAtLeastOnce ->yes ()) {
0 commit comments