-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathbug-6120.php
More file actions
84 lines (69 loc) · 1.5 KB
/
bug-6120.php
File metadata and controls
84 lines (69 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php // lint >= 8.0
declare(strict_types = 1);
namespace Bug6120;
use Generator;
use function PHPStan\Testing\assertType;
class HelloWorld
{
/**
* @var Generator<int, string> $gen
*/
private ?Generator $gen = null;
public function setGenerator(Generator $gen): void {
$this->gen = $gen;
}
public function sayHello(): void
{
while ($v = $this->gen?->current()) {
assertType('Generator<int, string, mixed, mixed>', $this->gen);
echo $v;
$this->gen->next();
}
}
}
final class Clazz
{
public int $foo = 0;
public function bar(?Clazz $clazz): void
{
$result = $clazz?->foo;
assertType('int|null', $result);
if ($result !== null) {
assertType('Bug6120\Clazz', $clazz);
assertType('int', $result);
$clazz->bar(null);
}
}
public function baz(?Clazz $clazz): void
{
$result = $clazz?->foo;
if ($result === null) {
assertType('Bug6120\Clazz|null', $clazz);
assertType('null', $result);
} else {
assertType('Bug6120\Clazz', $clazz);
assertType('int', $result);
}
}
public function withNullableProperty(?Clazz $clazz): void
{
$result = $clazz?->nullableProperty;
if ($result !== null) {
assertType('Bug6120\Clazz', $clazz);
assertType('string', $result);
}
}
public ?string $nullableProperty = null;
public function withMethodCall(?Clazz $clazz): void
{
$result = $clazz?->getFoo();
if ($result !== null) {
assertType('Bug6120\Clazz', $clazz);
assertType('int', $result);
}
}
public function getFoo(): int
{
return $this->foo;
}
}