Aladdin - Scala Bugtracking
[#1214] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Philipp Burak fixed 2007-07-16 14:05:55.0
subject unapply methods not handled in PartialFunctions
code
package test

object twice extends Application {

  object Twice {
    def apply(x: Int) = x * 2
    def unapply(x: Int) = if (x % 2 == 0) Some(x/2) else None
  }

  val patterns: PartialFunction[Int, Unit] = {
    case Twice(y) => println("twice "+y)
  }

  println(patterns.isDefinedAt(6))
}
what happened
exception when traversing ((x$0: Int) => x$0 match {
  case twice.this.Twice.unapply()  ((y @ _)) => scala.this.Predef.println("twice ".+(\
y))
})
exception when traversing private[this] val patterns: PartialFunction[Int,Unit] = ((x$0: Int) => x$0 match {
  case twice.this.Twice.unapply()  ((y @ _)) => scala.this.Predef.println("twice ".+(\
y))
})
...

Exception in thread "main" java.lang.Error: unexpected tree: class scala.tools.nsc.ast.Trees$UnApply
twice.this.Twice.unapply()  ((y @ _))
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:2737)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2769)
        at scala.tools.nsc.typechecker.Typers$Typer.typedPattern(Typers.scala:2830)
        at scala.tools.nsc.typechecker.Typers$Typer.typedCase(Typers.scala:1274)
...
what expected Successful compilation
[back to overview]
Changes of this bug report
Philipp  edited on  2007-07-16 14:07:03.0
Burak  edited on  2007-08-14 18:10:55.0