File tree Expand file tree Collapse file tree 2 files changed +12
-23
lines changed Expand file tree Collapse file tree 2 files changed +12
-23
lines changed Original file line number Diff line number Diff line change @@ -151,31 +151,12 @@ public function traverse(callable $cb): Type
151
151
152
152
public function traverseSimultaneously (Type $ right , callable $ cb ): Type
153
153
{
154
- $ types = [];
155
- $ changed = false ;
156
-
157
- if (!$ right instanceof UnionType) {
158
- return $ this ;
159
- }
160
-
161
- if (count ($ this ->getTypes ()) !== count ($ right ->getTypes ())) {
154
+ $ newType = parent ::traverseSimultaneously ($ right , $ cb );
155
+ if ($ newType === $ this ) {
162
156
return $ this ;
163
157
}
164
158
165
- foreach ($ this ->getSortedTypes () as $ i => $ leftType ) {
166
- $ rightType = $ right ->getSortedTypes ()[$ i ];
167
- $ newType = $ cb ($ leftType , $ rightType );
168
- if ($ leftType !== $ newType ) {
169
- $ changed = true ;
170
- }
171
- $ types [] = $ newType ;
172
- }
173
-
174
- if ($ changed ) {
175
- return TypeUtils::toBenevolentUnion (TypeCombinator::union (...$ types ));
176
- }
177
-
178
- return $ this ;
159
+ return TypeUtils::toBenevolentUnion ($ newType );
179
160
}
180
161
181
162
}
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ public static function dataChangeStringIntoNonEmptyString(): iterable
57
57
new IntegerType (),
58
58
new FloatType (),
59
59
]),
60
- '(int|string) ' ,
60
+ '(int|non-empty- string) ' ,
61
61
];
62
62
63
63
yield [
@@ -104,6 +104,14 @@ public static function dataDescriptionBased(): iterable
104
104
105
105
return $ right ;
106
106
};
107
+
108
+ yield [
109
+ '__benevolent<object|int> ' ,
110
+ '1|2|3 ' ,
111
+ $ chooseScalarSubtype ,
112
+ '(1|2|3|object) ' ,
113
+ ];
114
+
107
115
yield [
108
116
'object|int ' ,
109
117
'1|2|3 ' ,
You can’t perform that action at this time.
0 commit comments