Thanks to visit codestin.com
Credit goes to github.com

Skip to content

else branch ignored when determining array key type #9004

@greg0ire

Description

@greg0ire

Bug report

Using version 1.10.3, a code snippet when an array key is sometimes initialized to a string, some other times completed as an array results in the array key always being considered an array.

Code snippet that reproduces the problem

https://phpstan.org/r/9560820d-70e1-4af0-a70e-da4774f84e8c

Expected output

There should IMO be no issue here, and the dumped type should be array{}|array{hi: non-empty-array<int, 42>|'hello'}

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

I was happy to be able to reproduce the issue easily thanks to the playground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions