Skip to content

Commit bfa4708

Browse files
phpstan-botclaude
andcommitted
Add tests for $this->i ?? -1 inside both MyClass and MyClassUninitialized
Addresses review feedback: tests verify that $this->prop access inside the class does not produce false positive warnings for either initialized or uninitialized typed properties. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1a121e8 commit bfa4708

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public function testBug14393(): void
375375
$this->analyse([__DIR__ . '/data/bug-14393.php'], [
376376
[
377377
'Property Bug14393\MyClass::$i (int) on left side of ?? is not nullable.',
378-
17,
378+
27,
379379
],
380380
]);
381381
}

tests/PHPStan/Rules/Variables/data/bug-14393.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55
class MyClass
66
{
77
public int $i = 10;
8+
9+
public function doFoo(): void
10+
{
11+
var_dump($this->i ?? -1);
12+
}
813
}
914

1015
class MyClassUninitialized
1116
{
1217
public int $i;
18+
19+
public function doFoo(): void
20+
{
21+
var_dump($this->i ?? -1);
22+
}
1323
}
1424

1525
$o = new MyClass();

0 commit comments

Comments
 (0)