Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BusterNeece opened this issue Sep 5, 2021 · 8 comments · Fixed by phpstan/phpstan-src#992
Labels
Milestone

Comments

@BusterNeece
Copy link

BusterNeece commented Sep 5, 2021

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

@ondrejmirtes ondrejmirtes added this to the Generics milestone Sep 5, 2021
@jrmajor
Copy link

jrmajor commented Sep 22, 2021

Adding my reproduction I've created for #5677 (I think it's a bit simpler):

https://phpstan.org/r/0391a032-1553-47a8-88ad-c0f528d8dd3d

@mitelg
Copy link

mitelg commented Oct 11, 2021

I also have some trouble with generics and null
see this discussion 🙂 #5686

@alexander-schranz
Copy link

alexander-schranz commented Jan 25, 2022

I think I'm running into the same issue as I'm trying to use:

@template T of string|null

https://phpstan.org/r/90499164-0265-4b6a-89de-b311ddcb82c4

The type seems to be handled correctly. I'm just getting:

PHPDoc tag @template T for method HelloWorld::getEffectiveDimensionAttributes() with bound type null is not supported.

A more simpler usecase is: https://phpstan.org/r/9e0eebc8-a3e5-4cc9-9fbf-e182e71fdd93

/cc @ondrejmirtes as it seems to correct analyzed can the bound type null message be removed?

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-18: PHPDoc tag @template T for method HelloWorld::getEffectiveDimensionAttributes() with bound type null is not supported.
+No errors

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-12: PHPDoc tag @template T for method HelloWorld::getEffectiveDimensionAttributes() with bound type null is not supported.
+No errors

@alexander-schranz
Copy link

Thank you @ondrejmirtes and @arnaud-lb 👍

@jrmajor
Copy link

jrmajor commented Feb 4, 2022

Thank you!

@github-actions
Copy link

github-actions bot commented Mar 8, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants