1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
object patternUnsoundness extends App { class C[+T] case class D[S](_s: S) extends C[S] { var s: S = _s } val x = new D[String]("abc") val y: C[Object] = x y match { case d @ D(x) => d.s = new Integer(1) } val z: String = x.s // ClassCast exception }