Skip to content

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

Merged
merged 12 commits into from
Jan 16, 2020

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Jul 15, 2019

@liufengyun liufengyun changed the title Fix #6849: support urrefutable sequence match Fix #6849: support irrefutable sequence match Jul 15, 2019
@odersky
Copy link
Contributor

odersky commented Dec 12, 2019

@liufengyun Can we revive this before the release? It seems this is important functionality.

@odersky odersky closed this Dec 12, 2019
@odersky odersky reopened this Dec 12, 2019
@liufengyun liufengyun force-pushed the fix-6490 branch 2 times, most recently from b3b0b55 to f0b38e1 Compare December 13, 2019 12:39
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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

@@ -0,0 +1 @@
8: Pattern Match Exhaustivity: Foo(Nil)
Copy link
Contributor

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()?

Copy link
Contributor Author

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.
Copy link
Contributor Author

@liufengyun liufengyun left a 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)
Copy link
Contributor Author

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.

@nicolasstucki nicolasstucki merged commit 376f5b0 into scala:master Jan 16, 2020
@nicolasstucki nicolasstucki deleted the fix-6490 branch January 16, 2020 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler crash on irrefutable unapplySeq Document irrefutable unapply in pattern matching
5 participants