Skip to content

Wrong assignation to ArrayAccess&SomeOtherType not reported #6184

@julienfalque

Description

@julienfalque

Bug report

When assigning a wrong new value to a variable of type ArrayAccess, the error is not reported if the type of the variable includes an intersection with another type.

Code snippet that reproduces the problem

class Foo
{
    /** @var \ArrayAccess<int, string> */
    private $collection1;

    /** @var \ArrayAccess<int, string>&\Countable */
    private $collection2;

    public function foo(): void
    {
        $this->collection1[] = 1;
        $this->collection2[] = 2;
    }
}

https://phpstan.org/r/8142895e-0a04-44b6-82c9-e1eed898da54

Expected output

Both assignations should be reported as they don't accept int.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions