Aladdin - Scala Bugtracking
[#406] project: compiler priority: high category: bug
submitter assigned to status date submitted
Martin Burak fixed 2005-03-07 13:09:40.0
subject Pattern matcher generates wrong code
code
object Test with Application {

  class Type;
  case class A() extends Type;
  case class B() extends Type;
  case class C() extends Type;

  def foo(x: Type, y: Type) = Pair(x, y) match {
    case Pair(A(), A()) 
       | Pair(A(), B()) 
       | Pair(B(), A()) 
       | Pair(B(), B()) =>
      System.out.println("3")
    case Pair(C(), C()) =>
      System.out.println("4")
    case Pair(A(), _)
       | Pair(B(), _) =>
      System.out.println("7")
    case _ =>
      System.out.println("8")
  }

  foo(A(), C())
}
what happened
prints: 8
what expected should have printed: 7. Note that the problem goes away if we split the alternative in the last pattern into two cases, i.e. case Pair(A(), _) => System.out.println("7") case Pair(B(), _) => System.out.println("7") works correctly.
[back to overview]
Changes of this bug report
Burak  edited on  2005-03-07 15:19:46.0

top-down nondeterministic pattern, similar to #188 (which affects the SequenceMatcher), only that this time, it's the old PatternMatcher which is affected.

To be detected and solved by new pattern matching scheme...

Burak  edited on  2005-06-10 18:38:19.0