Skip to content

Commit 8354ecb

Browse files
phpstan-botondrejmirtes
authored andcommitted
Add regression test for #12998
Closes phpstan/phpstan#12998
1 parent 2f03f56 commit 8354ecb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
{
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)