File tree 3 files changed +48
-0
lines changed
tests/PHPStan/Rules/Comparison
3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -489,4 +489,13 @@ public function testBug9007(): void
489
489
$ this ->analyse ([__DIR__ . '/data/bug-9007.php ' ], []);
490
490
}
491
491
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
+
492
501
}
Original file line number Diff line number Diff line change @@ -9,3 +9,11 @@ function (): void {
9
9
1 => 'up '
10
10
};
11
11
};
12
+
13
+ function (): void {
14
+ $ result = match (rand (1 , 3 )) {
15
+ 1 => 'foo ' ,
16
+ 2 => 'bar ' ,
17
+ 3 => 'baz '
18
+ };
19
+ };
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments