-
Notifications
You must be signed in to change notification settings - Fork 548
Add throw point for UnhandledMatchError
#1056
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
f986a0f to
0494d32
Compare
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.
This isn't sufficient. It's possible that the match handles all the cases and doesn't throw the exception, even without the default cause.
See the rule on how I figure that out:
phpstan-src/src/Rules/Comparison/MatchExpressionRule.php
Lines 82 to 91 in d0ab72a
| if (!$hasDefault && !$nextArmIsDead) { | |
| $remainingType = $node->getEndScope()->getType($matchCondition); | |
| if (!$remainingType instanceof NeverType) { | |
| $errors[] = RuleErrorBuilder::message(sprintf( | |
| 'Match expression does not handle remaining %s: %s', | |
| $remainingType instanceof UnionType ? 'values' : 'value', | |
| $remainingType->describe(VerbosityLevel::value()), | |
| ))->build(); | |
| } | |
| } |
Additionally, I'd like the linked error to not be reported if the match is surrounded by a try-catch for UnhandledMatchError.
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.
Thanks! I wasn't aware of this rule. I'll try to fix it sometime this week.
Traversed parents to find try-catch, but not sure this is a good way. Also, maybe this error should be suppressed if there is an explicit |
ddd20b4 to
95d480b
Compare
|
Thank you! The |
fixes phpstan/phpstan#6115