File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments