File tree 2 files changed +35
-1
lines changed
tests/PHPStan/Reflection/data
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,22 @@ public static function decideType(
130
130
131
131
$ resultType = $ type ->isSuperTypeOf (TemplateTypeHelper::resolveToBounds ($ phpDocType ))->yes () ? $ phpDocType : $ type ;
132
132
133
- if (TypeCombinator::containsNull ($ type )) {
133
+ if ($ type instanceof UnionType) {
134
+ $ addToUnionTypes = [];
135
+ foreach ($ type ->getTypes () as $ innerType ) {
136
+ if (!$ innerType ->isSuperTypeOf ($ resultType )->no ()) {
137
+ continue ;
138
+ }
139
+
140
+ $ addToUnionTypes [] = $ innerType ;
141
+ }
142
+
143
+ if (count ($ addToUnionTypes ) > 0 ) {
144
+ $ type = TypeCombinator::union ($ resultType , ...$ addToUnionTypes );
145
+ } else {
146
+ $ type = $ resultType ;
147
+ }
148
+ } elseif (TypeCombinator::containsNull ($ type )) {
134
149
$ type = TypeCombinator::addNull ($ resultType );
135
150
} else {
136
151
$ type = $ resultType ;
Original file line number Diff line number Diff line change @@ -59,4 +59,23 @@ public function doBar(): array|false
59
59
60
60
}
61
61
62
+ /**
63
+ * @param array<int, string> $foo
64
+ */
65
+ public function doBaz (array |false $ foo ): void
66
+ {
67
+ assertType ('array<int, string>|false ' , $ foo );
68
+ assertNativeType ('array|false ' , $ foo );
69
+
70
+ assertType ('array<int, string>|false ' , $ this ->doLorem ());
71
+ }
72
+
73
+ /**
74
+ * @return array<int, string>
75
+ */
76
+ public function doLorem (): array |false
77
+ {
78
+
79
+ }
80
+
62
81
}
You can’t perform that action at this time.
0 commit comments