Skip to content

Refine criterion when to skip identifiers in pattern constructors #15367

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 1 commit into from
Jun 6, 2022

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 3, 2022

There's a strange and almost forgotten rule that disqualifies method symbols
from direct lookup when the identifier is the constructor of a pattern. This
is done to make code like this work:

class List[T]:
  def :: (that: T): List[T]
  def f(...) = this match
    case x :: xs => ...
object `::`:
  def unapply...

Without the rule, the :: in the pattern would resolve to the :: method
in List which does not have an unapply. We need to skip that method to get
to the outer :: object.

The rule plays badly with export forwarders, which are methods, and therefore
were ineligible for pattern constructurs. We now change the rule so that methods
are also accepted as unqualified unapply prefixes as long as they are parameterless.

Fixes #15347

There's a strange and almost forgotten rule that disqualifies method symbols
from direct lookup when the identifier is the constructor of a pattern. This
is done to make code like this work:
```
class List[T]:
  def :: (that: T): List[T]
  def f(...) = this match
    case x :: xs => ...
object `::`:
  def unapply...
```
Without the rule, the `::` in the pattern would resolve to the `::` method
in `List` which does not have an `unapply`. We need to skip that method to get
to the outer `::` object.

The rule plays badly with export forwarders, which are methods, and therefore
were ineligible for pattern constructurs. We now change the rule so that methods
are also accepted as unqualified `unapply` prefixes as long as they are parameterless.

Fixes scala#15347
@odersky odersky requested a review from noti0na1 June 6, 2022 09:13
Copy link
Member

@noti0na1 noti0na1 left a comment

Choose a reason for hiding this comment

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

LGTM

@noti0na1 noti0na1 merged commit ec74aa4 into scala:main Jun 6, 2022
@noti0na1 noti0na1 deleted the fix-15347 branch June 6, 2022 10:50
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
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.

Unable to pattern match an exported enum
3 participants