Pattern matching on type parameter T raises the unchecked warning
scala> def f[T](v: List[Any]): List[T] = v.collect { case x: T => x }
^
warning: abstract type pattern T is unchecked since it is eliminated by erasure
def f[T](v: List[Any]): List[T]
which one might try to resolve with ClassTag
scala> def f[T: scala.reflect.ClassTag](v: List[Any]): List[T] = v.collect { case x: T => x }
def f[T](v: List[Any])(implicit evidence$1: scala.reflect.ClassTag[T]): List[T]
which resolves the warning for simple class-based types
scala> f[String](List(42, "a"))
val res7: List[String] = List(a)
however now the unchecked warning becomes hidden even for types with parameterised types that have erased components at run-time
f[List[String]](List(List(42)))
val res9: List[List[String]] = List(List(42)) // oops!
How can we continue to raise the unchecked warning in the latter case?