Skip to content

False positive Property HelloWorld::$bug (WeakMap<stdClass, stdClass>) does not accept WeakMap<object, mixed>|WeakMap<stdClass, stdClass>. #12250

@netpok

Description

@netpok

Bug report

Hello this issue is very similar to #5551. Phpstan reports an error when new WeakMap is assigned to a templated variable using the null coalesce assignment operator.

I tried to fix this and I could get it working by adding AssignOp\Coalesce to the NewAssignedToPropertyVisitor.php and it passes all tests however I'm not sure whether this is a good solution or not because the coalesce assignment is conditional while the current ones are not.

I made a draft PR about this: phpstan/phpstan-src#3728.

Code snippet that reproduces the problem

https://phpstan.org/r/0b3630b5-8631-4fd7-938f-31d4c04d0666

Expected output

no error

Did PHPStan help you today? Did it make you happy in any way?

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions