Skip to content

Property $a (Ds\Set<stdClass>) does not accept Ds\Set<mixed> #6757

@simPod

Description

@simPod

Bug report

Since I cannot type new Set<string>() in php, it was handy that when assigning new instance that accepts generic arguments into a property, it would infer property's type.

The following used to work:

use Ds\Set;
use stdClass;

final class A
{
    /** @var Set<stdClass> */
    public Set $a;

    public function __construct()
    {
        $this->a = new Set();
    }
}

which avoided a lot of boilerplate code:

- $this->a = new Set();
+ /** @var Set<string> $set */
+ $set = new Set();
+ $this->a = $set;

but now gives

Property My\App\A::$a (Ds\Set) does not accept Ds\Set.

Code snippet that reproduces the problem

I tried to reproduce in playground but without success. Created reproducible example here

https://github.com/simPod/phpstan-reproduce https://phpstan.org/r/a33d1182-7157-463a-a2c5-9ff4fafe0ab8

Expected output

No errors

This behaviour is since v1.4.7

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions