Skip to content
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(#15784): ident rule for pat match was too strict #19501

Merged
merged 2 commits into from
Jan 22, 2024

Conversation

i10416
Copy link
Contributor

@i10416 i10416 commented Jan 21, 2024

close #15784

Scala 2 allows backticked identifier and capital identifier in pattern match, but Scala 3 mistakenly prohibited them.

For example, the following code is valid in Scala 2,

List(42) match {
  case List(_, Rest @ _*) => Rest
  case List(_, `Rest` @ _*) => `Rest`
  _ => ???
}

whereas it resulted in Not Found Rest error in Scala 3.

This is because the condition to detect wildcard pattern was so strict that it chose the wrong match arm; case _ => ifExpr.

close scala#15784

Scala 2 allows backticked identifier and capital identifier in pattern
match, but Scala 3 mistakenly prohibited them.

For example, the following code is valid in Scala 2,

```scala
List(42) match {
  case List(_, Rest @ _*) => Rest
  case List(_, `Rest` @ _*) => `Rest`
  _ => ???
}
```
whereas it resulted in `Not Found Rest` error in Scala 3.

This is because the condition to detect wildcard pattern was so strict
that it chose the wrong match arm; `case _ => ifExpr`.
@Kordyjan Kordyjan requested a review from sjrd January 22, 2024 15:16
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick on formatting, but otherwise LGTM.

Comment on lines 1 to 2
def i15784 = List(42) match
case List(_, Rest @ `a`) => Rest // error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: please follow the standard 2-space indent in the test files as well:

Suggested change
def i15784 = List(42) match
case List(_, Rest @ `a`) => Rest // error
def i15784 = List(42) match
case List(_, Rest @ `a`) => Rest // error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed them.
09abbd6

@sjrd sjrd merged commit ca18f4a into scala:main Jan 22, 2024
19 checks passed
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur added a commit that referenced this pull request Jun 28, 2024
#20848)

Backports #19501 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

Scala 3 does not take arbitrary id in pattern @ binding
3 participants