Skip to content

PHPStan loses type resolution when creating a union of int and numeric-string #10092

@Ocramius

Description

@Ocramius

Bug report

When using azjezz/psl, the Psl\Type\union() is used to create a union type out of two (or more) Psl\Type\TypeInterface<T> instances.

Roughly: function union(TypeInterface<T>, TypeInterface<U>): TypeInterface<T|U>.

This works fine, but PHPStan seems to have trouble in computing union types for somehow close types like int and numeric-string, leading to inference of int|string rather than int|numeric-string.

Similarly, it cannot compute 0 and positive-int, leading to int being inferred, rather than 0|int<1, max> or int<0, max>.

Code snippet that reproduces the problem

https://phpstan.org/r/749e7db4-8d56-4d2d-9faa-1d3d32790ba0

Expected output

  • union(int, numeric-string) should become int|numeric-string (currently produces int|string)
  • union(0, int<1, max>) should become 0|int<1, max> (currently produces int)

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

Thanks for your continued work on this: makes PHP bearable :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions