Skip to content

Commit 4e35f59

Browse files
Add non regression test for #8620
1 parent 1506ba9 commit 4e35f59

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ public function dataFileAsserts(): iterable
11551155
}
11561156
yield from $this->gatherAssertTypes(__DIR__ . '/data/pathinfo.php');
11571157
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8568.php');
1158+
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/DeadCode/data/bug-8620.php');
11581159
}
11591160

11601161
/**

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@ public function testBug7188(): void
131131
]);
132132
}
133133

134+
public function testBug8620(): void
135+
{
136+
$this->treatPhpDocTypesAsCertain = true;
137+
$this->analyse([__DIR__ . '/data/bug-8620.php'], []);
138+
}
139+
134140
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug8620;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
public function nullCoalesceAndConcatenation (?int $a = null): int
10+
{
11+
$key = ($a ?? "x") . "-";
12+
assertType('non-falsy-string', $key);
13+
if ($key === "x-") { return 0; }
14+
15+
return 1;
16+
}
17+
18+
public function nullCoalesce (?int $a = null): int
19+
{
20+
$key = ($a ?? "");
21+
assertType("''|int", $key);
22+
if ($key === "") { return 0; }
23+
24+
return 1;
25+
}
26+
27+
public function nullCheck (?int $a = null): int
28+
{
29+
if (is_null ($a)) { return 0; }
30+
31+
return 1;
32+
}
33+
}

0 commit comments

Comments
 (0)