bug icon indicating copy to clipboard operation
bug copied to clipboard

pattern matching over covariant GADT unsound

Open scabug opened this issue 11 years ago • 15 comments

The following code produces a ClassCastException at runtime:

object Test extends App {
  sealed trait Node[+A]
  case class L[C,D](f: C => D) extends Node[C => D]

  def test[A,B](n: Node[A => B]): A => B = n match {
    case l: L[c,d] => l.f
  }

  println {
    test(new L[Int,Int](identity) with Node[Nothing]: Node[Int => String])(3): String
  }
}

scabug avatar May 05 '14 16:05 scabug