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

soundness issue with path-dependent type on `null` path #9633

Open
scabug opened this Issue Jan 29, 2016 · 2 comments

Comments

Projects
None yet
1 participant
@scabug
Copy link

scabug commented Jan 29, 2016

The null path p below can be used to collapse the subtyping lattice through bad bounds. This snippet was found jointly with Ross Tate who asked whether our recent soundness result for DOT would carry over in presence of null values.

object world extends App {
  trait A { type L <: Nothing }
  trait B { type L >: Any}
  def toL(b: B)(x: Any): b.L = x
  val p: B with A = null

  // we can create a value of type Nothing
  println(toL(p)("hello"): Nothing)
  // at runtime: java.lang.ClassCastException: java.lang.String cannot be cast to scala.runtime.Nothing$

  // variation on a theme...
  def cast[T,U](x: T): U = toL(p)(x)

  println(cast[Int,String](1) + "hello")
  // at runtime: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

  println(cast[String,Int => Int]("hello")(1))
  // at runtime: java.lang.ClassCastException: java.lang.String cannot be cast to scala.Function1
}
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 29, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9633?orig=1
Reporter: @namin
Affected Versions: 2.11.7, 2.12.0-M3

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Feb 10, 2016

@szeiger said (edited on Feb 18, 2016 12:24:34 PM UTC):
Related information from Dotty: http://scala-lang.org/blog/2016/02/17/scaling-dot-soundness.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment