@@ -63,107 +63,109 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
63
63
$ fallback = new TArray ([Type::getArrayKey (), Type::getMixed ()]);
64
64
$ array_arg = $ call_args [0 ]->value ?? null ;
65
65
if (!$ array_arg ) {
66
- $ first_arg_array = $ fallback ;
66
+ $ first_arg_arrays = [ $ fallback] ;
67
67
} else {
68
68
$ first_arg_type = $ statements_source ->node_data ->getType ($ array_arg );
69
- if (!$ first_arg_type || $ first_arg_type ->isMixed ()) {
70
- $ first_arg_array = $ fallback ;
69
+ if (!$ first_arg_type || $ first_arg_type ->isMixed () || !( $ arrays = $ first_arg_type -> getArrays ()) ) {
70
+ $ first_arg_arrays = [ $ fallback] ;
71
71
} else {
72
- $ first_arg_array = $ first_arg_type ->hasArray ()
73
- && ($ array_atomic_type = $ first_arg_type ->getArray ())
74
- && ($ array_atomic_type instanceof TArray
75
- || $ array_atomic_type instanceof TKeyedArray)
76
- ? $ array_atomic_type
77
- : $ fallback ;
72
+ $ first_arg_arrays = $ arrays ;
78
73
}
79
74
}
80
75
81
- if ($ first_arg_array instanceof TArray) {
82
- $ inner_type = $ first_arg_array ->type_params [1 ];
83
- $ key_type = $ first_arg_array ->type_params [0 ];
84
- } else {
85
- $ inner_type = $ first_arg_array ->getGenericValueType ();
86
- $ key_type = $ first_arg_array ->getGenericKeyType ();
87
-
88
- if (!isset ($ call_args [1 ]) && $ first_arg_array ->fallback_params === null ) {
89
- $ had_one = count ($ first_arg_array ->properties ) === 1 ;
90
-
91
- $ new_properties = array_filter (
92
- array_map (
93
- static function ($ keyed_type ) use ($ statements_source , $ context ) {
94
- $ prev_keyed_type = $ keyed_type ;
95
-
96
- $ keyed_type = AssertionReconciler::reconcile (
97
- new Truthy (),
98
- $ keyed_type ,
99
- '' ,
100
- $ statements_source ,
101
- $ context ->inside_loop ,
102
- [],
103
- null ,
104
- $ statements_source ->getSuppressedIssues (),
105
- );
76
+ $ out_types = [];
77
+ foreach ($ first_arg_arrays as $ first_arg_array ) {
78
+ if ($ first_arg_array instanceof TArray) {
79
+ $ inner_type = $ first_arg_array ->type_params [1 ];
80
+ $ key_type = $ first_arg_array ->type_params [0 ];
81
+ } else {
82
+ $ inner_type = $ first_arg_array ->getGenericValueType ();
83
+ $ key_type = $ first_arg_array ->getGenericKeyType ();
84
+
85
+ if (!isset ($ call_args [1 ]) && $ first_arg_array ->fallback_params === null ) {
86
+ $ had_one = count ($ first_arg_array ->properties ) === 1 ;
87
+
88
+ $ new_properties = array_filter (
89
+ array_map (
90
+ static function ($ keyed_type ) use ($ statements_source , $ context ) {
91
+ $ prev_keyed_type = $ keyed_type ;
92
+
93
+ $ keyed_type = AssertionReconciler::reconcile (
94
+ new Truthy (),
95
+ $ keyed_type ,
96
+ '' ,
97
+ $ statements_source ,
98
+ $ context ->inside_loop ,
99
+ [],
100
+ null ,
101
+ $ statements_source ->getSuppressedIssues (),
102
+ );
103
+
104
+ return $ keyed_type ->setPossiblyUndefined (!$ prev_keyed_type ->isAlwaysTruthy ());
105
+ },
106
+ $ first_arg_array ->properties ,
107
+ ),
108
+ static fn ($ keyed_type ) => !$ keyed_type ->isNever ()
109
+ );
106
110
107
- return $ keyed_type ->setPossiblyUndefined (!$ prev_keyed_type ->isAlwaysTruthy ());
108
- },
109
- $ first_arg_array ->properties ,
110
- ),
111
- static fn ($ keyed_type ) => !$ keyed_type ->isNever ()
112
- );
111
+ if (!$ new_properties ) {
112
+ $ out_types []= Type::getEmptyArrayAtomic ();
113
+ continue ;
114
+ }
113
115
114
- if (!$ new_properties ) {
115
- return Type::getEmptyArray ();
116
+ $ out_types []= new TKeyedArray (
117
+ $ new_properties ,
118
+ null ,
119
+ $ first_arg_array ->fallback_params ,
120
+ $ first_arg_array ->is_list && $ had_one ,
121
+ );
116
122
}
117
-
118
- return new Union ([new TKeyedArray (
119
- $ new_properties ,
120
- null ,
121
- $ first_arg_array ->fallback_params ,
122
- $ first_arg_array ->is_list && $ had_one ,
123
- )]);
124
123
}
125
- }
126
124
127
- if (!isset ($ call_args [1 ])) {
128
- $ inner_type = AssertionReconciler::reconcile (
129
- new Truthy (),
130
- $ inner_type ,
131
- '' ,
132
- $ statements_source ,
133
- $ context ->inside_loop ,
134
- [],
135
- null ,
136
- $ statements_source ->getSuppressedIssues (),
137
- );
138
-
139
- if ($ first_arg_array instanceof TKeyedArray
140
- && $ first_arg_array ->is_list
141
- && $ key_type ->isSingleIntLiteral ()
142
- && $ key_type ->getSingleIntLiteral ()->value === 0
143
- ) {
144
- return Type::getList (
125
+ if (!isset ($ call_args [1 ])) {
126
+ $ inner_type = AssertionReconciler::reconcile (
127
+ new Truthy (),
145
128
$ inner_type ,
129
+ '' ,
130
+ $ statements_source ,
131
+ $ context ->inside_loop ,
132
+ [],
133
+ null ,
134
+ $ statements_source ->getSuppressedIssues (),
146
135
);
147
- }
148
136
149
- if ($ key_type ->getLiteralStrings ()) {
150
- $ key_type = $ key_type ->getBuilder ()->addType (new TString )->freeze ();
151
- }
137
+ if ($ first_arg_array instanceof TKeyedArray
138
+ && $ first_arg_array ->is_list
139
+ && $ key_type ->isSingleIntLiteral ()
140
+ && $ key_type ->getSingleIntLiteral ()->value === 0
141
+ ) {
142
+ $ out_types []= Type::getListAtomic (
143
+ $ inner_type ,
144
+ );
145
+ continue ;
146
+ }
152
147
153
- if ($ key_type -> getLiteralInts ()) {
154
- $ key_type = $ key_type -> getBuilder ()-> addType ( new TInt )-> freeze ();
155
- }
148
+ if ($ inner_type -> isUnionEmpty ()) {
149
+ $ out_types []= Type:: getEmptyArrayAtomic ();
150
+ }
156
151
157
- if ($ inner_type -> isUnionEmpty ()) {
158
- return Type:: getEmptyArray ();
159
- }
152
+ if ($ key_type -> getLiteralStrings ()) {
153
+ $ key_type = $ key_type -> getBuilder ()-> addType ( new TString )-> freeze ();
154
+ }
160
155
161
- return new Union ([
162
- new TArray ([
156
+ if ($ key_type ->getLiteralInts ()) {
157
+ $ key_type = $ key_type ->getBuilder ()->addType (new TInt )->freeze ();
158
+ }
159
+
160
+ $ out_types []= new TArray ([
163
161
$ key_type ,
164
162
$ inner_type ,
165
- ]),
166
- ]);
163
+ ]);
164
+ }
165
+ }
166
+
167
+ if ($ out_types ) {
168
+ return new Union ([$ out_types ]);
167
169
}
168
170
169
171
if (!isset ($ call_args [2 ])) {
0 commit comments