Skip to content

Commit 8f37360

Browse files
clxmstaabstaabm
authored andcommitted
reproduce bug 1396
1 parent 4241667 commit 8f37360

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎tests/PHPStan/Analyser/NodeScopeResolverTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ public function dataFileAsserts(): iterable
13351335
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9293.php');
13361336
yield from $this->gatherAssertTypes(__DIR__ . '/data/nullsafe-vs-scalar.php');
13371337
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8517.php');
1338+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-1396.php');
13381339
}
13391340

13401341
/**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug1396;
4+
5+
use PHPStan\Type\Constant\ConstantStringType;
6+
use PHPStan\Type\ConstantScalarType;
7+
use function PHPStan\Testing\assertType;
8+
9+
class HelloWorld
10+
{
11+
public function doFoo(
12+
ConstantScalarType $constantType
13+
): SpecifiedTypes
14+
{
15+
assertType('bool|float|int|string|null', $constantType->getValue());
16+
17+
if ($constantType->getValue() === null) {
18+
return new SpecifiedTypes();
19+
}
20+
21+
assertType('bool|float|int|string', $constantType->getValue());
22+
23+
if (
24+
$constantType instanceof ConstantStringType
25+
) {
26+
assertType('string', $constantType->getValue());
27+
}
28+
assertType('bool|float|int|string', $constantType->getValue());
29+
}
30+
}

0 commit comments

Comments
 (0)