Skip to content

Commit

Permalink
Add non regression test for #8620
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Jan 3, 2023
1 parent 1506ba9 commit 4e35f59
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ public function dataFileAsserts(): iterable
}
yield from $this->gatherAssertTypes(__DIR__ . '/data/pathinfo.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8568.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/DeadCode/data/bug-8620.php');
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,10 @@ public function testBug7188(): void
]);
}

public function testBug8620(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-8620.php'], []);
}

}
33 changes: 33 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-8620.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types = 1);

namespace Bug8620;

use function PHPStan\Testing\assertType;

class HelloWorld
{
public function nullCoalesceAndConcatenation (?int $a = null): int
{
$key = ($a ?? "x") . "-";
assertType('non-falsy-string', $key);
if ($key === "x-") { return 0; }

return 1;
}

public function nullCoalesce (?int $a = null): int
{
$key = ($a ?? "");
assertType("''|int", $key);
if ($key === "") { return 0; }

return 1;
}

public function nullCheck (?int $a = null): int
{
if (is_null ($a)) { return 0; }

return 1;
}
}

0 comments on commit 4e35f59

Please sign in to comment.