Aladdin - Scala Bugtracking
[#796] project: compiler priority: low category: bug
submitter assigned to status date submitted
Martin Burak fixed 2006-11-03 17:50:07.0
subject unapply problem with nested objects
code
object Test extends Application {

  object Twice {
    def apply(x: int) = x * 2
    def unapply(x: int): Option[Tuple1[int]] =
      if (x % 2 == 0) Some(Tuple1(x / 2))
      else None
  }

  def test(x: int) = x match {
    case Twice(y) => "x is two times "+y
    case _ => "x is odd"
  }

  Console.println(test(3))
  Console.println(test(4))

}

  
what happened
/home/odersky/scala/test/files/new> nsc Twice.scala -Xunapply -prompt
Twice.scala:11 error: pattern type is incompatibe with expected type;
 found   : Test.this.Twice.type (with underlying type object Test.this.Twice)
 required: scala.Int
    case Twice(y) => "x is two times "+y
         ^
r)esume, a)bort: 
what expected The problem seems to be related to the fact that now Twice is nested inside Test. Compare with bug795, which passes the typechecker.
[back to overview]
Changes of this bug report
Martin  edited on  2006-11-03 17:50:40.0
Burak  edited on  2006-11-10 19:00:35.0