Skip to content

Appending to array with int-range key produces warning #9131

@MoonE

Description

@MoonE

Bug report

<?php 
class A
{
    /** @var array<int<0, max>, string> */
    public array $l = [];

    public function add(string $s): void {
        $this->l[] = $s;
    }
}

8 | Property A::$l (array<int<0, max>, string>) does not accept non-empty-array<int, string>.

Code snippet that reproduces the problem

https://phpstan.org/r/bb35caea-1af5-43f2-bec1-6f7d578218f3

Expected output

No warning!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions