Skip to content

T[K] return type not reducing to a single type from array shape #7788

@mikeymike

Description

@mikeymike

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/ede7535a-4964-4b38-bbfe-c5d5c8cc1571

Expected output

The expectation was that the dumped type would result in 30|0 or int if it's generalised. Similar to psalm

Instead what we're getting is a union of all the types in the array, which then requires doc blocks or assertions I was hoping to avoid.

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

I've been able to wipe out a host of potential bugs while also providing more safety around generic classes, so yeah, this has made me very happy 😄

Side note, I'd be happy to take a stab at looking at resolving this with some pointers, I've tried to grok the codebase but couldn't nail down the right place to look for something like this.

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