I'm trying to figure out what is going on on this piece of code, trying to figure out if there is something that I donβt understand, or if it is a compiler error or an unintuitive specification, 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 a List[Int]
with an erase type, it cannot tell the difference. But it is strange if I call typeErause2(List(2,5,6))
, I get "uh?"
, and I donβt understand why it does not match List[String]
, as it was before. If I use List[_]
instead in the second function, it will be able to match it correctly, which makes me think that this is a bug in scalac.
I am using Scala 2.9.1
source share