Skip to content

Overloaded method hides scala.:: extractor #11421

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
adpi2 opened this issue Feb 15, 2021 · 0 comments · Fixed by #11429
Closed

Overloaded method hides scala.:: extractor #11421

adpi2 opened this issue Feb 15, 2021 · 0 comments · Fixed by #11429
Assignees
Milestone

Comments

@adpi2
Copy link
Member

adpi2 commented Feb 15, 2021

Compiler version

3.0.0-M3

Minimized code

class Foo {
  def ::(hd: String): Foo = ???
  def ::(hd: Boolean): Foo  = ???
  
  List(1, 2) match {
    case x :: tail => ()
    case _ => ()
  }
}

Output

[error] -- [E134] Type Mismatch Error: ~/ambiguous-reference/src/main/scala/foo.scala:8:11 
[error] 8 |    case x :: tail => ()
[error]   |           ^^
[error]   |  None of the overloaded alternatives of method :: in class Foo with types
[error]   |   (hd: Int): foo.Foo
[error]   |   (hd: String): foo.Foo
[error]   |  match expected type ?{ unapply: <?> }
[error] one error found

Expectation

It should compile by applying the scala.:: extractor.

Additional information

  • It does compile in Scala 2.13.4
  • The fact that :: is an overloaded method in class Foo plays a role, because the following code compiles:
class Foo {
  def ::(hd: String): Foo = ???
  
  List(1, 2) match {
    case x :: tail => ()
    case _ => ()
  }
}
@liufengyun liufengyun self-assigned this Feb 16, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Feb 16, 2021
The previous logic only skipped non-overloaded methods.

Fixes scala#11421
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants