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

Bug when pattern matching on existential values #9247

Open
scabug opened this issue Mar 24, 2015 · 4 comments
Open

Bug when pattern matching on existential values #9247

scabug opened this issue Mar 24, 2015 · 4 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) patmat
Milestone

Comments

@scabug
Copy link

scabug commented Mar 24, 2015

Existentials as arguments to unapply result in a compilation error:

Minimal example:

  trait Match {
    type X
    def unapply(x: X): Option[String]
  }

  def foo(m: Match): m.X => String = {
    case m(s) => s
  }

yields

an unapply result must have a member `def isEmpty: Boolean
[error]     case m(s) => s
[error]          ^
[error] one error found
[error] (compile:compile) Compilation failed

In contrast, a variant using universal types works just fine:

  trait Match[X] {
    def unapply(x: X): Option[String]
  }

  def foo[X](m: Match[X]): X => String = {
    case m(s) => s
  }

Might be related to the following issues:

@scabug
Copy link
Author

scabug commented Mar 24, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9247?orig=1
Reporter: Jonathan Brachthäuser (b-studios)
Affected Versions: 2.11.3, 2.11.4, 2.11.5, 2.11.6

@scabug
Copy link
Author

scabug commented Aug 11, 2016

Julien Richard-Foy (julienrf) said (edited on Aug 11, 2016 11:21:42 AM UTC):
Is there a workaround for this issue?

@scabug
Copy link
Author

scabug commented Aug 11, 2016

@paulp said:
Workaround:

  def foo[A](m: Match { type X = A }): A => String = {
    case m(s) => s
  }

@scabug
Copy link
Author

scabug commented Aug 12, 2016

Jonathan Brachthäuser (b-studios) said:
Workaround 2: Use dotty.

Just tried with 0.1-SNAPSHOT and it works perfectly fine.

@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@adriaanm adriaanm removed their assignment Sep 28, 2018
@smarter smarter added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) patmat
Projects
None yet
Development

No branches or pull requests

3 participants