-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ErrorType instead of throwing in match type "no cases" #18016
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
a53253a
to
1db8a3f
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.
Overall looks good. I have one minor comment.
@@ -3115,7 +3115,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer | |||
case xtree: untpd.NameTree => typedNamed(xtree, pt) | |||
case xtree => typedUnnamed(xtree) | |||
|
|||
val hadErroneus = result.tpe.isErroneous |
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.
val hadErroneus = result.tpe.isErroneous | |
val hadErroneous = result.tpe.isErroneous |
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.
isErroneous
look like it performs a type traversal, so it seems expensive for no reason in the happy path.
Consider storing val unsimplifiedType = result.tpe
instead, and only check unsimplifiedType.isErroneous
later, in the guard of case e: ErrorType
. This way, we avoid the traversal in the happy path where we don't get an ErrorType
.
1db8a3f
to
167c88d
Compare
167c88d
to
6b41901
Compare
Instead of throwing MatchTypeReductionError, return ErrorType(MatchTypeNoCases), which is a proper message as well. This avoids having to catch and ignore it as an exception. But it does require discovering it from type simplification and reporting it then - which replaces its reliance on catching TypeErrors. It also required handling scrutinees that are error types, which previously would always match the first case, due to FlexType semantics.
6b41901
to
9ae1598
Compare
Instead of throwing MatchTypeReductionError, return
ErrorType(MatchTypeNoCases), which is a proper message as well.
This avoids having to catch and ignore it as an exception. But it does
require discovering it from type simplification and reporting it then -
which replaces its reliance on catching TypeErrors.
It also required handling scrutinees that are error types, which
previously would always match the first case, due to FlexType semantics.