Skip to content

Union Type + Nullable yields "Expects TEntity(A|B)|null, TEntity(A|B)|null given" #5591

@BusterNeece

Description

@BusterNeece

Bug report

Hello! I'm having a counterintuitive moment after my recent PHPStan update where I'm getting an error message that reads out like:

  15     Parameter #1 $record of method App\TestClass<TEntity of App\Entity\Station|App\Entity\User>::innerMethod() expects
         (TEntity of App\Entity\Station|App\Entity\User)|null, (TEntity of App\Entity\Station|App\Entity\User)|null given.

Basically, it's saying it expected, and was given, the exact same type. It shouldn't be an error at all.

I think it's getting tripped up by the TEntity as A|B declaration, then later having TEntity|null being defined as a method parameter.

Was able to reproduce this via the web PHPStan tester. Can verify via my own local code that the same issue isn't present in 0.12.96 but is present in both 0.12.97 and 0.12.98.

Code snippet that reproduces the problem

https://phpstan.org/r/cc421f16-0749-407d-80ac-e05e7624d3f7

Expected output

No issues with the sample code.

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

PHPStan helps me every day! It's a wonderful tool and I'm proud to be one of its supporters. <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions