-
Notifications
You must be signed in to change notification settings - Fork 21
pattern matcher still allows unsound case class reconstruction #7886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7886?orig=1 |
@paulp said: |
@retronym said: |
@retronym said (edited on Nov 29, 2013 9:15:34 AM UTC):
|
@retronym said: https://gist.github.com/retronym/7704153 In that example, I've added the parent type The pattern matching inference unsoundly casts Unravel[_] to Unravel[Any]. |
@retronym said: |
@retronym said: 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 // java.lang.Integer cannot be cast to java.lang.String
}
} |
@retronym said: |
@retronym said: {
sealed trait Foo[A] {
def run: A =
this match {
case Map(elt, f) => f("Can I have some type safety please?x")
}
}
final case class Map[A,B](elt: A, f: A => B) extends Foo[B]
// expand the case class and a type error is issued, as per examples above.
// final class Map[A,B](val elt: A, val f: A => B) extends Foo[B]
// object Map {
// def unapply[A, B](m: Map[A, B]): Option[(A, A => B)] = Some((m.elt, m.f))
//}
} |
Note that without the second parameter to Unravel, this is correctly failed in 2.10 (but not in 2.9.)
But with it:
The text was updated successfully, but these errors were encountered: