Skip to content

dumpType should distinguish benevolent union types from normal unions #14770

@stof

Description

@stof

Feature request

Reading the php-internals about generics, I tried to figure out a case where some failing code was accepted by phpstan (see https://externals.io/message/130816#130883).
Reproducing it in the playground indeed showed it as passing: https://phpstan.org/r/1e03afaa-4271-431e-a93d-3e3070fc5d83

Adding type dumping to debug the issue got me confused about why it would not fail: https://phpstan.org/r/3256c9e6-16ed-494c-8f1d-d9b3275d08c2
Enforcing checks for benevolent union types made me realize the truth: the type I was dumping was not actually a int|string but a benevolent union: https://phpstan.org/r/b48d6911-725d-4ac0-87d8-33430b347e4f

It would be great if PHPStan\dumpType could actually give the info about a type being a benevolent union (at least when they are not treated like normal unions) to make such debugging easier.

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

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions