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
151151
152152 public function traverseSimultaneously (Type $ right , callable $ cb ): Type
153153 {
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 ) {
162156 return $ this ;
163157 }
164158
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 );
179160 }
180161
181162}
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ public static function dataChangeStringIntoNonEmptyString(): iterable
5757 new IntegerType (),
5858 new FloatType (),
5959 ]),
60- '(int|string) ' ,
60+ '(int|non-empty- string) ' ,
6161 ];
6262
6363 yield [
@@ -104,6 +104,14 @@ public static function dataDescriptionBased(): iterable
104104
105105 return $ right ;
106106 };
107+
108+ yield [
109+ '__benevolent<object|int> ' ,
110+ '1|2|3 ' ,
111+ $ chooseScalarSubtype ,
112+ '(1|2|3|object) ' ,
113+ ];
114+
107115 yield [
108116 'object|int ' ,
109117 '1|2|3 ' ,
You can’t perform that action at this time.
0 commit comments