File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
tests/PHPStan/Rules/Comparison Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,18 @@ public function tryRemove(Type $typeToRemove): ?Type
219219 if ($ classReflection ->isFinal () && $ genericObjectClassNames [0 ] === $ typeToRemove ->getValue ()) {
220220 return new NeverType ();
221221 }
222+
223+ if ($ classReflection ->getAllowedSubTypes () !== null ) {
224+ $ objectTypeToRemove = new ObjectType ($ typeToRemove ->getValue ());
225+ $ remainingType = TypeCombinator::remove ($ generic , $ objectTypeToRemove );
226+ if ($ remainingType instanceof NeverType) {
227+ return new NeverType ();
228+ }
229+
230+ if (!$ remainingType ->equals ($ generic )) {
231+ return new self ($ remainingType );
232+ }
233+ }
222234 }
223235 } elseif (count ($ genericObjectClassNames ) > 1 ) {
224236 $ objectTypeToRemove = new ObjectType ($ typeToRemove ->getValue ());
Original file line number Diff line number Diff line change @@ -453,6 +453,12 @@ public function testBug9534(): void
453453 ]);
454454 }
455455
456+ #[RequiresPhp('>= 8.0 ' )]
457+ public function testBug12241 (): void
458+ {
459+ $ this ->analyse ([__DIR__ . '/data/bug-12241.php ' ], []);
460+ }
461+
456462 #[RequiresPhp('>= 8.0 ' )]
457463 public function testBug13029 (): void
458464 {
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Bug12241 ;
6+
7+ /**
8+ * @phpstan-sealed Bar|Baz
9+ */
10+ abstract class Foo{}
11+
12+ final class Bar extends Foo{}
13+ final class Baz extends Foo{}
14+
15+ function (Foo $ foo ): string {
16+ return match ($ foo ::class) {
17+ Bar::class => 'Bar ' ,
18+ Baz::class => 'Baz ' ,
19+ };
20+ };
You can’t perform that action at this time.
0 commit comments