Skip to content

Generic template type & union don't play well together #4481

@vojtech-dobes

Description

@vojtech-dobes

Bug report

Given generic instance with specific template type T (eg. string), this instance can't be passed to generic parameter which specifies T as compatible union (eg. string|int).

Code snippet that reproduces the problem

https://phpstan.org/r/280fa009-69dc-4515-8b09-5bbaee07eb61

Expected output

Considering the more specific instance is clearly subset of the parameter type, I believe it should be accepted.

My real-life union was actually about nullable instance, eg. Foo|NULL.

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