Skip to content

Commit d3ee15a

Browse files
committed
expect errors
1 parent afe06dc commit d3ee15a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

tests/PHPStan/Analyser/nsrt/bug-14213.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,27 @@
66

77
class HelloWorld
88
{
9-
public static function coalesce_int_range(): void
9+
public static function coalesce_nonsensical(): void
10+
{
11+
$x0 = $x1 = $x2 = null;
12+
13+
if (rand(0, 1)) {
14+
$x0 = rand(0, 1);
15+
$x1 = rand(2, 3);
16+
$x2 = rand(4, 5);
17+
}
18+
19+
// either all 3 variables are null, or all have a int-range value
20+
$x = (
21+
$x0 ??
22+
$x1 ??
23+
$x2
24+
);
25+
26+
assertType('int<0, 1>|null', $x);
27+
}
28+
29+
public static function coalesce_int_ranges(): void
1030
{
1131
$x0 = $x1 = $x2 = null;
1232

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ public function testPr4372(): void
354354

355355
public function testBug14213(): void
356356
{
357-
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-14213.php'], []);
357+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-14213.php'], [
358+
[
359+
'Variable $x1 on left side of ?? always exists and is always null.',
360+
21,
361+
],
362+
]);
358363
}
359364

360365
}

0 commit comments

Comments
 (0)