Skip to content

Commit bcf00a2

Browse files
committed
Fix imprecise types after assignment when strict-types=1
1 parent b3d3386 commit bcf00a2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
use function PHPStan\Testing\assertNativeType;
4+
use function PHPStan\Testing\assertType;
5+
6+
class NarrowsNativeUnion {
7+
private readonly int|float $i;
8+
9+
public function __construct()
10+
{
11+
$this->i = getInt();
12+
assertType('int', $this->i);
13+
assertNativeType('int', $this->i);
14+
}
15+
16+
public function doFoo(): void {
17+
assertType('int', $this->i);
18+
assertNativeType('int', $this->i);
19+
}
20+
}
21+
22+
class NarrowsStaticNativeUnion {
23+
private static int|float $i;
24+
25+
public function __construct()
26+
{
27+
self::$i = getInt();
28+
assertType('int', self::$i);
29+
assertNativeType('int', self::$i);
30+
}
31+
32+
public function doFoo(): void {
33+
assertType('float|int', self::$i);
34+
assertNativeType('float|int', self::$i);
35+
}
36+
}
37+
38+
function getInt(): int {
39+
return 1;
40+
}

0 commit comments

Comments
 (0)