-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #6849: support irrefutable sequence match #6850
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
liufengyun
commented
Jul 15, 2019
•
edited
Loading
edited
- Fix Document irrefutable unapply in pattern matching #6490: Add spec for irrefutable extractors
- Fix Compiler crash on irrefutable unapplySeq #6849: support irrefutable sequence match
@liufengyun Can we revive this before the release? It seems this is important functionality. |
b3b0b55
to
f0b38e1
Compare
def unapplySeq(x: Any): ThreeStringExtract = new ThreeStringExtract("" + x) | ||
def unapplySeq(x: Any): Option[(List[Int], Double, Seq[Char])] = | ||
if ((x == null) || (x == "")) then None | ||
else Some(new ThreeStringExtract("" + x).get) |
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.
Should add extra tests rather than modify the old ones
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 added extra tests in other files. This test has to be adapted, as it does not conform to the protocol: the result type conforms to sequence match, thus it is irrefutable.
tests/patmat/i6490.check
Outdated
@@ -0,0 +1 @@ | |||
8: Pattern Match Exhaustivity: Foo(Nil) |
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.
Shouldn’t it be Pattern Match Exhaustivity: Foo()
?
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.
Now it prints Foo()
.
The mismatch is caused by an additional ConstFold during unpickling.
Now if the result type of an unapplySeq conforms to a sequence match, it will be taken as an irrefutable sequence match --- `isEmpty` and `get` defined on the type are ignored. Thus, we need to rewrite the test.
It's accidentally removed in conflict resolution.
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.
Updated
def unapplySeq(x: Any): ThreeStringExtract = new ThreeStringExtract("" + x) | ||
def unapplySeq(x: Any): Option[(List[Int], Double, Seq[Char])] = | ||
if ((x == null) || (x == "")) then None | ||
else Some(new ThreeStringExtract("" + x).get) |
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 added extra tests in other files. This test has to be adapted, as it does not conform to the protocol: the result type conforms to sequence match, thus it is irrefutable.