diff --git a/src/Parser/NewAssignedToPropertyVisitor.php b/src/Parser/NewAssignedToPropertyVisitor.php index 209e72730d..2e1cfc7437 100644 --- a/src/Parser/NewAssignedToPropertyVisitor.php +++ b/src/Parser/NewAssignedToPropertyVisitor.php @@ -12,7 +12,7 @@ final class NewAssignedToPropertyVisitor extends NodeVisitorAbstract public function enterNode(Node $node): ?Node { - if ($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignRef) { + if ($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignRef || $node instanceof Node\Expr\AssignOp\Coalesce) { if ( ($node->var instanceof Node\Expr\PropertyFetch || $node->var instanceof Node\Expr\StaticPropertyFetch) && $node->expr instanceof Node\Expr\New_ diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index dede3e9211..35492a29bc 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -651,6 +651,11 @@ public function testBug11275(): void ]); } + public function testBug12250(): void + { + $this->analyse([__DIR__ . '/data/bug-12250.php'], []); + } + public function testBug11617(): void { $this->checkExplicitMixed = true; diff --git a/tests/PHPStan/Rules/Properties/data/bug-12250.php b/tests/PHPStan/Rules/Properties/data/bug-12250.php new file mode 100644 index 0000000000..10c128150e --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-12250.php @@ -0,0 +1,31 @@ += 7.4 + +namespace Bug12250; + +class Model {} + +/** + * @template T of object|array + */ +class WeakAnalysingMap +{ + /** @var list */ + public array $values = []; +} + +class Reference +{ + /** @var WeakAnalysingMap */ + private static WeakAnalysingMap $analysingTheirModelMap; + + public function createAnalysingTheirModel(): Model + { + self::$analysingTheirModelMap ??= new WeakAnalysingMap(); + + $theirModel = new Model(); + + self::$analysingTheirModelMap->values[] = $theirModel; + + return end(self::$analysingTheirModelMap->values); + } +}