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
Type information lost when passing generic type of enum as argument #9084
Comments
Your original example doesn't show the problem you're describing, this does: https://phpstan.org/r/ace4e48a-b5e2-40a7-b191-c060db486d39 |
Why is Or did you add the |
|
Similarly, the closed issue #8322 was closed as a invalid with explanation that https://phpstan.org/r/b3f7353e-e4f9-4f8e-a21f-ca067a105d29 The expected return type |
Thank you for the clarification. That can work for a simple case like the original example. But, it will not work for a code like https://phpstan.org/r/daac5dbf-315c-4745-9810-0db8748fa4da But once the issue with the type detection is fixed, the linked example should also pass validation, without |
|
Yes it is, and But that is only a workaround, and it shouldn't be needed since |
It's not a valid issue, and it's not a workaround. |
But to be sure, asking the local variance expert @jiripudil: is this a bug or not? https://phpstan.org/r/b3f7353e-e4f9-4f8e-a21f-ca067a105d29 Thank you. |
That is a bug. It's just a wild guess, but I suspect it could be the same issue as in #9074 |
Alright, thanks, I'm gonna reopen it. Sorry for misleading, it looked like a legit report. |
Bug explained: #9074 (reply in thread) |
@JoyceBabu After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.1 – 8.2 (3 errors)
+PHP 8.1 – 8.2 (4 errors)
==========
+27: Enum case MassUnit::MilliGram type float doesn't match the "int" type.
68: Dumped type: Value<UnitType::Mass>
69: Parameter #1 $value of function duplicate expects Value<UnitType>, Value<UnitType::Mass> given.
70: Dumped type: Value<UnitType> Full reportPHP 8.1 – 8.2 (4 errors)
PHP 7.2 – 8.0 (1 error)
|
I have updated the sample code to fix the unrelated error. |
@JoyceBabu After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.1 – 8.2 (3 errors)
+PHP 8.1 – 8.2 (4 errors)
==========
+27: Enum case MassUnit::MilliGram value 0.001 does not match the "int" type.
68: Dumped type: Value<UnitType::Mass>
69: Parameter #1 $value of function duplicate expects Value<UnitType>, Value<UnitType::Mass> given.
70: Dumped type: Value<UnitType> Full reportPHP 8.1 – 8.2 (4 errors)
PHP 7.2 – 8.0 (1 error)
|
Closes phpstan/phpstan#8166 Closes phpstan/phpstan#8127 Closes phpstan/phpstan#7944 Closes phpstan/phpstan#7283 Closes phpstan/phpstan#6653 Closes phpstan/phpstan#6196 Closes phpstan/phpstan#9084 Closes phpstan/phpstan#8683 Closes phpstan/phpstan#8074 Closes phpstan/phpstan#7984 Closes phpstan/phpstan#7301 Closes phpstan/phpstan#7087 Closes phpstan/phpstan#5594 Closes phpstan/phpstan#5592 Closes phpstan/phpstan#9472 Closes phpstan/phpstan#9764 Closes phpstan/phpstan#10092
Closes phpstan/phpstan#8166 Closes phpstan/phpstan#8127 Closes phpstan/phpstan#7944 Closes phpstan/phpstan#7283 Closes phpstan/phpstan#6653 Closes phpstan/phpstan#6196 Closes phpstan/phpstan#9084 Closes phpstan/phpstan#8683 Closes phpstan/phpstan#8074 Closes phpstan/phpstan#7984 Closes phpstan/phpstan#7301 Closes phpstan/phpstan#7087 Closes phpstan/phpstan#5594 Closes phpstan/phpstan#5592 Closes phpstan/phpstan#9472 Closes phpstan/phpstan#9764 Closes phpstan/phpstan#10092
Closes phpstan/phpstan#8166 Closes phpstan/phpstan#8127 Closes phpstan/phpstan#7944 Closes phpstan/phpstan#7283 Closes phpstan/phpstan#6653 Closes phpstan/phpstan#6196 Closes phpstan/phpstan#9084 Closes phpstan/phpstan#8683 Closes phpstan/phpstan#8074 Closes phpstan/phpstan#7984 Closes phpstan/phpstan#7301 Closes phpstan/phpstan#7087 Closes phpstan/phpstan#5594 Closes phpstan/phpstan#5592 Closes phpstan/phpstan#9472 Closes phpstan/phpstan#9764 Closes phpstan/phpstan#10092
Last night I came up with the idea that we mostly shouldn't generalize the generic type variables, except when they're in object generics, like Here's the resulting PR: phpstan/phpstan-src#2818 We can't do this for objects, because I want The new behaviour now only applies to bleeding edge (https://phpstan.org/blog/what-is-bleeding-edge) so definitely enable it to get the taste of the future 👍 |
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. |
Bug report
When I pass an argument of type
T
, whereT
isT of EnumType::*
to a function, the type of the changed parameter is changed toT<EnumType>
instead ofT<actual enum type>
.For example, if I pass
Foo<Bar::Baz>
as a function parameter to a function/** @param S $foo */ function foobar($foobar);
, type ofS
is detected asFoo<Bar>
, notFoo<Bar::Baz>
. So, the parameter fails to match its own generic type. Instead an message about template covariance is reported.Code snippet that reproduces the problem
https://phpstan.org/r/6056f0bd-2f52-456f-8bb1-bd746091fafb
Expected output
The generic type
S
is the type of the passed argument. So it should should always pass validation.Did PHPStan help you today? Did it make you happy in any way?
The text was updated successfully, but these errors were encountered: