File tree 3 files changed +29
-1
lines changed
3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -1005,7 +1005,20 @@ private static function scrapeStringProperties(
1005
1005
if (!$ type ->as_type ) {
1006
1006
$ combination ->class_string_types ['object ' ] = new TObject ();
1007
1007
} else {
1008
- $ combination ->class_string_types [$ type ->as ] = $ type ->as_type ;
1008
+ if (isset ($ combination ->class_string_types [$ type ->as ])
1009
+ && $ combination ->class_string_types [$ type ->as ] instanceof TNamedObject
1010
+ ) {
1011
+ if ($ combination ->class_string_types [$ type ->as ]->extra_types === []) {
1012
+ // do nothing, existing type is wider or the same
1013
+ } elseif ($ type ->as_type ->extra_types === []) {
1014
+ $ combination ->class_string_types [$ type ->as ] = $ type ->as_type ;
1015
+ } else {
1016
+ // todo: figure out what to do with class-string<A&B>|class-string<A&C>
1017
+ $ combination ->class_string_types [$ type ->as ] = $ type ->as_type ;
1018
+ }
1019
+ } else {
1020
+ $ combination ->class_string_types [$ type ->as ] = $ type ->as_type ;
1021
+ }
1009
1022
}
1010
1023
} elseif ($ type instanceof TLiteralString) {
1011
1024
if ($ combination ->strings !== null && count ($ combination ->strings ) < $ literal_limit ) {
Original file line number Diff line number Diff line change @@ -940,6 +940,13 @@ public function providerTestValidTypeCombination(): array
940
940
'"0" ' ,
941
941
],
942
942
],
943
+ 'unionOfClassStringAndClassStringWithIntersection ' => [
944
+ 'class-string<IFoo> ' ,
945
+ [
946
+ 'class-string<IFoo> ' ,
947
+ 'class-string<IFoo & IBar> ' ,
948
+ ],
949
+ ],
943
950
];
944
951
}
945
952
Original file line number Diff line number Diff line change @@ -1148,6 +1148,14 @@ public function testIntMaskOfWithValidValueOf(): void
1148
1148
$ this ->assertSame ('int-mask-of<value-of<A::FOO>> ' , $ docblock_type ->getId ());
1149
1149
}
1150
1150
1151
+ public function testUnionOfClassStringAndClassStringWithIntersection (): void
1152
+ {
1153
+ $ this ->assertSame (
1154
+ 'class-string<IFoo> ' ,
1155
+ (string ) Type::parseString ('class-string<IFoo>|class-string<IFoo&IBar> ' ),
1156
+ );
1157
+ }
1158
+
1151
1159
public function testReflectionTypeParse (): void
1152
1160
{
1153
1161
if (!function_exists ('Psalm\Tests\someFunction ' )) {
You can’t perform that action at this time.
0 commit comments