Skip to content

Commit 38203e7

Browse files
committed
test readonly class
1 parent a8528fd commit 38203e7

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

tests/PHPStan/Analyser/nsrt/bug-13321.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.1
22

33
namespace Bug13321;
44

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php // lint >= 8.2
2+
3+
namespace Bug13321b;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
public function __construct(public string $value)
10+
{
11+
}
12+
}
13+
14+
readonly class Bar
15+
{
16+
public function __construct(
17+
private ?Foo $foo,
18+
)
19+
{
20+
}
21+
22+
public function bar(): void
23+
{
24+
if ($this->foo === null) {
25+
return;
26+
}
27+
if ($this->foo->value === '') {
28+
return;
29+
}
30+
31+
assertType(Foo::class, $this->foo);
32+
assertType('non-empty-string', $this->foo->value);
33+
34+
$test = function () {
35+
assertType(Foo::class, $this->foo);
36+
assertType('string', $this->foo->value);
37+
};
38+
39+
$test();
40+
}
41+
42+
}

0 commit comments

Comments
 (0)