File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
tests/PHPStan/Rules/Comparison Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -416,6 +416,17 @@ public function testBug13303(): void
416416 ]);
417417 }
418418
419+ #[RequiresPhp('>= 8.0 ' )]
420+ public function testBug12998 (): void
421+ {
422+ $ this ->analyse ([__DIR__ . '/data/bug-12998.php ' ], [
423+ [
424+ 'Match expression does not handle remaining value: class-string<T of Bug12998\C|Bug12998\D> ' ,
425+ 37 ,
426+ ],
427+ ]);
428+ }
429+
419430 #[RequiresPhp('>= 8.0 ' )]
420431 public function testBug9534 (): void
421432 {
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Bug12998 ;
6+
7+ final class A {}
8+ final class B {}
9+
10+ class C {}
11+ class D {}
12+
13+ /**
14+ * Final classes with template: match IS exhaustive
15+ *
16+ * @template T of A|B
17+ *
18+ * @param class-string<T> $class
19+ */
20+ function fooFinal (string $ class ): string
21+ {
22+ return match ($ class ) {
23+ A::class => 'a ' ,
24+ B::class => 'b ' ,
25+ };
26+ }
27+
28+ /**
29+ * Non-final classes with template: match can't be exhaustive
30+ *
31+ * @template T of C|D
32+ *
33+ * @param class-string<T> $class
34+ */
35+ function fooNonFinal (string $ class ): string
36+ {
37+ return match ($ class ) {
38+ C::class => 'c ' ,
39+ D::class => 'd ' ,
40+ };
41+ }
You can’t perform that action at this time.
0 commit comments