Skip to content

Infering array-keys is erroneous #7423

@drupol

Description

@drupol

Hi,

Recently I've been working on a tool that I was using internally to generate random typed values.
I pushed it online 3 days ago so I can use it everywhere easily, find the tool here: https://github.com/loophp/typed-generators

I noticed an issue while working on the ArrayType and I'm opening this issue to know if this issue is legit.
I reproduced the issue on the PHPStan playground here: https://phpstan.org/r/518a80cb-3a3d-460a-8bc5-e0791d732063
Sorry for the size of the snippet, while writing this issue I'm still looking for a reproducer with smaller amount of code.
I added some comments in the snippet to show you were PHPStan fails to infer the proper type.

IMHO, I think there is a bug somewhere because when changing the type definition from ArrayType<TKey|VKey, T|V> to ArrayType<VKey|TKey, T|V> (line 118), the PHPStan output is different.

The same snippet in PSalm is behaving correctly: https://psalm.dev/r/b48de03f7e

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions