Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Parser/NewAssignedToPropertyVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class NewAssignedToPropertyVisitor extends NodeVisitorAbstract
#[Override]
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_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,4 +1003,15 @@ public function testCloneWith(): void
]);
}

#[RequiresPhp('>= 8.0')]
public function testBug12250(): void
{
$this->analyse([__DIR__ . '/data/bug-12250.php'], []);
}

public function testBug4525(): void
{
$this->analyse([__DIR__ . '/data/bug-4525.php'], []);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-12250.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php // lint >= 8.0

namespace Bug12250;

class HelloWorld
{
/**
* @var \WeakMap<\stdClass, \stdClass>
*/
protected \WeakMap $bug, $ok;

public function bug(): void
{
$this->bug ??= new \WeakMap();
$this->ok = new \WeakMap();
}
}
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-4525.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php // lint >= 7.4

namespace Bug4525;

use SplObjectStorage;

class HelloWorld
{
/**
* @var SplObjectStorage<\DateTime, \DateTimeImmutable>
*/
private SplObjectStorage $map;

public function sayHello(): void
{
$this->map = new SplObjectStorage();
}

/** @phpstan-return SplObjectStorage<\DateTime, \DateTimeImmutable> */
public function getMap(): SplObjectStorage
{
return $this->map ??= new SplObjectStorage();
}
}
Loading