-
Notifications
You must be signed in to change notification settings - Fork 506
Fix check generic mixed type based on config v2 #2885
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
Fix check generic mixed type based on config v2 #2885
Conversation
src/Rules/RuleLevelHelper.php
Outdated
@@ -62,7 +62,7 @@ private function transformCommonType(Type $type): Type | |||
} | |||
|
|||
return TypeTraverser::map($type, function (Type $type, callable $traverse) { | |||
if ($type instanceof TemplateMixedType) { | |||
if ($type instanceof TemplateMixedType && $this->checkExplicitMixed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TemplateMixedType
extends explicit MixedType
, so I made its behavior consistent with that.
I wonder whether @template T
and @template T of mixed
should be implicit/explicit respectively. But I assume that the implicit mixed exists mainly for untyped legacy code. So in that sense it seems right to me for both of them to be considered explicit, even though it feels slightly inconsistent with how it works for non-generic parameters. Especially, considering that checkImplicitMixed
is off even with level 9.
{ | ||
|
||
/** | ||
* @param callable(mixed): void $cb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I wasn't able to figure out how to make a callable with implicit mixed parameter. But if it's impossible to make one, then it doesn't matter how it behaves and so there's no need to test it.
cece3bf
to
4321f19
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I mostly like this, but I'd prefer the new behaviour only for bleeding edge, because this leads to more errors being eeported.
Please lead to the new behaviour only when newRuleLevelHelper
is enabled, otherwise use the old behaviour. You don't need to test it, it should be obvious from the diff (that you're adding new branches to the code and otherwise not changing anything else).
b58c879
to
c4f1d74
Compare
If the build passes I'm gonna merge this :) |
c4f1d74
to
f4b1b48
Compare
Thank you! |
This is an alternative to #2809 . This time I was able to limit the changes to
RuleLevelHelper
(it kind of makes me wonder how I missed this option in the first place).The goal is to handle
TemplateMixedType
similarly to explicitMixedType
with respect tocheckExplicitMixed
. Here is an example of the issues in as many cases as I can think of https://phpstan.org/r/0b58afa8-fd01-4991-922e-d46037106135 . As you can see, even the regular mixed type is not covered completely, but that's a matter for another PR(s).These are the results for the linked playground code in this branch: