Skip to content

Commit b4a6eb4

Browse files
committed
Regression tests
Closes phpstan/phpstan#6064 Closes phpstan/phpstan#9457
1 parent 6d152ae commit b4a6eb4

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,13 @@ public function testBug9007(): void
489489
$this->analyse([__DIR__ . '/data/bug-9007.php'], []);
490490
}
491491

492+
public function testBug9457(): void
493+
{
494+
if (PHP_VERSION_ID < 80100) {
495+
$this->markTestSkipped('Test requires PHP 8.1.');
496+
}
497+
498+
$this->analyse([__DIR__ . '/data/bug-9457.php'], []);
499+
}
500+
492501
}

tests/PHPStan/Rules/Comparison/data/bug-6064.php

+8
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ function (): void {
99
1 => 'up'
1010
};
1111
};
12+
13+
function (): void {
14+
$result = match(rand(1, 3)) {
15+
1 => 'foo',
16+
2 => 'bar',
17+
3 => 'baz'
18+
};
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug9457;
4+
5+
class Randomizer {
6+
function bool(): bool {
7+
return rand(0, 1) === 1;
8+
}
9+
10+
public function doFoo(?self $randomizer): void
11+
{
12+
// Correct
13+
echo match ($randomizer?->bool()) {
14+
true => 'true',
15+
false => 'false',
16+
null => 'null',
17+
};
18+
19+
// Correct
20+
echo match ($randomizer?->bool()) {
21+
true => 'true',
22+
false, null => 'false or null',
23+
};
24+
25+
// Unexpected error
26+
echo match ($randomizer?->bool()) {
27+
false => 'false',
28+
true, null => 'true or null',
29+
};
30+
}
31+
}

0 commit comments

Comments
 (0)