Why does this fail to compile (or work?):
case class A(x: Int)
class B extends A(5)
(new B) match {
case A(_) => println("found A")
case _ => println("something else happened?")
}
The compiler error is:
constructor cannot be instantiated to expected type; found : blevins.example.App.A required: blevins.example.App.B
Note that this compiles and runs as expected:
(new B) match {
case a: A => println("found A")
case _ => println("something else happened?")
}
ADDENDUM
Just for reference, this compiles and runs fine:
class A(val x: Int)
object A {
def unapply(a: A) = Some(a.x)
}
class B extends A(5)
(new B) match {
case A(i) => println("found A")
case _ => println("something else happened?")
}