Skip to content

Incorrect "Offset might not exist" on list<> when higher index does exist #12605

Description

@RobertMe

Bug report

When doing an isset($list[3]) (where $list is a list<...>) it can be assumed that all lower indexes (0, 1, 2) do exist as well. Because if those didn't exist the variable wouldn't be a list anymore (but just an array<int, ...>). Yet PHPStan errors in this case when accessing any of the lower indexes.

Code snippet that reproduces the problem

https://phpstan.org/r/06841d0c-74f6-46ac-b780-7c101e48e58f

Expected output

No errors. dumpType results in &hasOffsetValue(1, int)&hasOffsetValue(2, int)&hasOffsetValue(3, int).

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

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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