In the below code I keep getting this error — pattern type is incompatible with expected type;
Which I feel is incorrect. Is this a possible bug in Scala 2? Anywhere I can read more about it?
sealed trait Foo[A] { self =>
def eval: Option[A] =
self match {
case Foo.Number => Option(1)
case Foo.Text => Option("Ok")
}
}
object Foo {
case object Number extends Foo[Int]
case object Text extends Foo[String]
}
println("ok!")
Weirdly it works when eval
is implemented in the companion object Foo