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

Guarded pattern with existential causes bad matching #1434

Closed
scabug opened this issue Oct 18, 2008 · 3 comments
Closed

Guarded pattern with existential causes bad matching #1434

scabug opened this issue Oct 18, 2008 · 3 comments
Milestone

Comments

@scabug
Copy link

scabug commented Oct 18, 2008

The following code prints "B" instead of the expected result "C":

object MatchTest {
  class A[T] { val op = null }
  class B extends A[Any]
  class C extends B

  def f(o: AnyRef) = o match {
    case a: A[_] if(a.op != null) => "with op"
    case c: C => "C"
    case b: B => "B"
  }

  def main(args: Array[String]) = println(f(new C))
}

Case "a" is never matched because the if() guard always fails but using the existential type A[_] in case a also causes the match for case c to fail. Removing the type parameter on A entirely or matching against A[Any] (which gets erased anyway) in case a results in the correct output "C".

This is with Scala 2.7.2RC3.

@scabug
Copy link
Author

scabug commented Oct 18, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1434?orig=1
Reporter: @szeiger
Assignee: @DRMacIver

@scabug
Copy link
Author

scabug commented Jun 1, 2009

@szeiger said:
I just ran into the same problem again with some new code where it occurs without an if() guard but I wasn't able to reproduce it in a test case which is simple enough to post.

@scabug
Copy link
Author

scabug commented Jul 5, 2009

@paulp said:
Fixed in r18212.

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

No branches or pull requests

1 participant