-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4999: allow pattern matching against by-name arguments #5012
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 #4999: allow pattern matching against by-name arguments #5012
Conversation
In this testcase `tp` is `TermRef(NoPrefix, xs)` so widenExpr does nothing, but `widenTermRefExpr` is appropriate.
Since ExprType are unstable, we can keep stable TermRef alone, in case this provides more info to the pattern matcher/exhaustivity checker.
@@ -116,7 +116,7 @@ object PatternMatcher { | |||
/** Widen type as far as necessary so that it does not refer to a pattern- | |||
* generated variable. | |||
*/ | |||
private def sanitize(tp: Type): Type = tp.widenExpr match { | |||
private def sanitize(tp: Type): Type = tp.widenIfUnstable match { |
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.
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.
Yeah the first commit uses widenTermRefExpr
. Maybe @liufengyun can think of examples where widening singletons would make a difference?
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.
What about x match { case _: x.type => ... }
?
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.
We concluded with @smarter that there is no need to widen singleton types
@@ -116,7 +116,7 @@ object PatternMatcher { | |||
/** Widen type as far as necessary so that it does not refer to a pattern- | |||
* generated variable. | |||
*/ | |||
private def sanitize(tp: Type): Type = tp.widenExpr match { | |||
private def sanitize(tp: Type): Type = tp.widenIfUnstable match { |
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.
We concluded with @smarter that there is no need to widen singleton types
In this testcase
tp
isTermRef(NoPrefix, xs)
sowidenExpr
does nothing, butwidenTermRefExpr
is appropriate.