Skip to content

Remove irrefutable match pattern #10782

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

Closed

Conversation

changvvb
Copy link
Contributor

Fixes #10614
Remove irrefutable match pattern, so that scala3 has the same behavior as scala2.

Copy link
Contributor

@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.

Thanks @changvvb 👍

Instead of removing the tests, can we adapt them?

@b-studios
Copy link
Contributor

Great, thanks @changvvb ! Could you maybe also adjust the docs (Sources) accordingly.

@changvvb
Copy link
Contributor Author

Thanks @changvvb 👍

Instead of removing the tests, can we adapt them?

I thought they are meaningless because almost all of these tests commented by // error are compiled successfully.
Deleting these tests is really too rough. I try to inspect them.

@liufengyun
Copy link
Contributor

Thanks @changvvb 👍
Instead of removing the tests, can we adapt them?

I thought they are meaningless because almost all of these tests commented by // error are compiled successfully.
Deleting these tests is really too rough. I try to inspect them.

Fair enough. I thought Scala 2.13.4 issues a warning for the code below and we need to do the same as well:

scala > val Some(x) = Option(3)

But it does not.

@changvvb
Copy link
Contributor Author

Fair enough. I thought Scala 2.13.4 issues a warning for the code below and we need to do the same as well:

scala > val Some(x) = Option(3)

But it does not.

I tried to compile val Some(x) = Option(3) both on scala 2.13.4 and scala 3, but no warning appeared.
On the other hand, they both show warning with Option(3) match { case Some(x) => x }

@liufengyun
Copy link
Contributor

Fair enough. I thought Scala 2.13.4 issues a warning for the code below and we need to do the same as well:

scala > val Some(x) = Option(3)

But it does not.

I tried to compile val Some(x) = Option(3) both on scala 2.13.4 and scala 3, but no warning appeared.
On the other hand, they both show warning with Option(3) match { case Some(x) => x }

Yes, I got the same result. Then it's fine to remove them. Could you please rebase and update the docs, as suggested by @b-studios ?

@changvvb
Copy link
Contributor Author

@b-studios @liufengyun
http://dotty.epfl.ch/docs/reference/changed-features/pattern-bindings.html introduce case for for expressions

This code gives a compile-time error in Scala 3.1 whereas in Scala 2 the list elems is filtered to retain only the elements of tuple type that match the pattern (x, y). The filtering functionality can be obtained in Scala 3 by prefixing the pattern with case:
for (case (x, y) <- elems) yield (y, x) // returns List((2, 1), (4, 3))

and

Generator ::= [‘case’] Pattern1 ‘<-’ Expr

Now, is it necessary to retain it?

@liufengyun
Copy link
Contributor

@b-studios @liufengyun
http://dotty.epfl.ch/docs/reference/changed-features/pattern-bindings.html introduce case for for expressions

This code gives a compile-time error in Scala 3.1 whereas in Scala 2 the list elems is filtered to retain only the elements of tuple type that match the pattern (x, y). The filtering functionality can be obtained in Scala 3 by prefixing the pattern with case:
for (case (x, y) <- elems) yield (y, x) // returns List((2, 1), (4, 3))

and

Generator ::= [‘case’] Pattern1 ‘<-’ Expr

Now, is it necessary to retain it?

I think it's worthwhile to keep it and make sure it works.

@anatoliykmetyuk anatoliykmetyuk added this to the 3.0.0-M3 milestone Dec 14, 2020
@liufengyun
Copy link
Contributor

@changvvb Thanks for your PR. We need to meet a deadline tomorrow, therefore I made a new PR #10793 .

@liufengyun liufengyun removed this from the 3.0.0-M3 milestone Dec 14, 2020
@changvvb
Copy link
Contributor Author

@changvvb Thanks for your PR. We need to meet a deadline tomorrow, therefore I made a new PR #10793 .

OK, I will close this PR.
I see they are different implements while #10793 drop Pattern2 [‘:’ Type | Ascription] ‘=’ Expr syntax but keep irrefutable match pattern in Scala 3.

@changvvb changvvb closed this Dec 15, 2020
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.

Usage of @unchecked annotation with val is inconsistent between Scala 2 and 3
4 participants