File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,18 @@ private function isSuperTypeOfDefault(Type $type): IsSuperTypeOfResult
6666 return IsSuperTypeOfResult::createYes ();
6767 }
6868
69+ if ($ this ->equals ($ type )) {
70+ return IsSuperTypeOfResult::createYes ();
71+ }
72+
73+ if ($ type instanceof UnionType) {
74+ foreach ($ type ->getTypes () as $ innerType ) {
75+ if ($ this ->equals ($ innerType )) {
76+ return IsSuperTypeOfResult::createYes ();
77+ }
78+ }
79+ }
80+
6981 if ($ type instanceof LateResolvableType) {
7082 $ type = $ type ->resolve ();
7183 }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Type ;
4+
5+ use PHPStan \Type \Constant \ConstantStringType ;
6+ use PHPStan \Type \IntegerType ;
7+ use PHPStan \Type \NeverType ;
8+ use PHPStan \Type \UnionType ;
9+ use PHPUnit \Framework \TestCase ;
10+
11+ class LateResolvableTypeTraitTest extends TestCase
12+ {
13+
14+ public function testIsSuperTypeOfForConditional (): void
15+ {
16+ $ conditional = new ConditionalTypeForParameter (
17+ '$operator ' ,
18+ new ConstantStringType ('in ' ),
19+ new IntegerType (),
20+ new NeverType (),
21+ false ,
22+ );
23+
24+ $ this ->assertSame ('Yes ' , $ conditional ->isSuperTypeOf ($ conditional )->describe ());
25+
26+ $ unionWithConditional = new UnionType ([
27+ new StringType (),
28+ $ conditional ,
29+ ]);
30+
31+ $ this ->assertSame ('Yes ' , $ conditional ->isSuperTypeOf ($ unionWithConditional )->describe ());
32+ }
33+
34+ }
You can’t perform that action at this time.
0 commit comments