Skip to content

Commit 795c612

Browse files
phpstan-botclaude
andcommitted
Add non-regression test for phpstan/phpstan#4846
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c529b65 commit 795c612

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ public function testBug13921(): void
377377
]);
378378
}
379379

380+
public function testBug4846(): void
381+
{
382+
$this->analyse([__DIR__ . '/data/bug-4846.php'], [
383+
[
384+
'Property Bug4846\Foo::$alwaysString (string) on left side of ?? is not nullable.',
385+
13,
386+
],
387+
]);
388+
}
389+
380390
public function testBug14393(): void
381391
{
382392
$this->analyse([__DIR__ . '/data/bug-14393.php'], [
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug4846;
4+
5+
class Foo
6+
{
7+
public string $alwaysString = '';
8+
9+
public ?string $nullableString = null;
10+
}
11+
12+
function (Foo $foo): void {
13+
echo $foo->alwaysString ?? 'string';
14+
15+
echo $foo->nullableString ?? 'string';
16+
};

0 commit comments

Comments
 (0)