I'm trying to figure out what's going on on this piece of code, trying to figure out if there is something I don't understand or if it is a compiler bug or unintuitive spec, let's define these two almost identical functions:
def typeErause1(a: Any) = a match {
case x: List[String] => "stringlists"
case _ => "uh?"
}
def typeErause2(a: Any) = a match {
case List(_, _) => "2lists"
case x: List[String] => "stringlists"
case _ => "uh?"
}
now if I call typeErause1(List(2,5,6)) I get "stringlists" because even if it is actually List[Int] with type erasure it is not able to tell the difference. But strangely if I call typeErause2(List(2,5,6)) I get "uh?" and I don't understand why it is not matching List[String] like it did before. If I use List[_] instead on the second function it is able to match it correctly which makes me think this is a bug in scalac.
I'm using Scala 2.9.1