-
Notifications
You must be signed in to change notification settings - Fork 548
Add early termination for NeverType match expression
#1078
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
Conversation
src/Analyser/NodeScopeResolver.php
Outdated
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.
I'm not sure about this fix. What should be done instead is that these situations should be caught by the if ($exprType instanceof NeverType && $exprType->isExplicit()) { instead.
"Implicit" NeverType is for example when you try to intersect two incompatible types (string&int). "Explicit" mixed is when you have a throw expression, function with @return never and similar.
This means that the explicitness of "NeverType" gets lost when we have a match expression with "explicit never" arms, and that's something that should be fixed instead.
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.
Thank you for the review and informative examples. I'll try fixing in that way!
ddd20b4 to
95d480b
Compare
|
The cause is here, phpstan-src/src/Type/TypeCombinator.php Lines 134 to 137 in 51e2df3
phpstan-src/src/Type/TypeCombinator.php Line 304 in 51e2df3
but not sure how to fix yet. Also, the comment says that it's transforming phpstan-src/src/Type/TypeCombinator.php Line 272 in 51e2df3
but NeverType is not handled there.
I think it can be handled like the comment says, and But if I fix like that, test fails here with phpstan-src/tests/PHPStan/Analyser/data/bug-1516.php Lines 1 to 37 in 86fd620
|
|
Have to take more time breaking and fixing |
0812e21 to
221c050
Compare
|
Hi, I've took the liberty to push a change here. Some tests still fail but I like it beter. Before TypeCombinator removed NeverType from Right now we leave NeverType in there so if But some tests currently fail and I don't know why. Please debug that, thanks :) Please read more about what's going on in TypeCombinator here: https://phpstan.org/developing-extensions/type-system (especially https://phpstan.org/developing-extensions/type-system#type-normalization). |
|
@ondrejmirtes phpstan-src/src/Type/TypeCombinator.php Line 268 in c4ac24b
but not transformed actually. By adding phpstan-src/tests/PHPStan/Analyser/data/bug-1516.php Lines 1 to 37 in 86fd620
This one failed because it has a different reason related to but the handling for
is expecting a implicit NeverType
I hope this fix is in the right direction. I'll add a regression test for |
|
The thing is - NeverType is already handled by if ($b->isSuperTypeOf($a)->yes()) {
return [null, $b];
}
if ($a->isSuperTypeOf($b)->yes()) {
return [$a, null];
}The root issue was that some types wrongly responded to isSuperTypeOf with NeverType. So I addressed the root issue and merged it: 99951ac Thank you. |
|
Thank you. |
fixes phpstan/phpstan#6257
fixes phpstan/phpstan#6251