Skip to content

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

@scabug

Description

@scabug

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
}

Activity

scabug

scabug commented on Jan 29, 2016

@scabug
Author

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

scabug

scabug commented on Feb 10, 2016

@scabug
Author

@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

added this to the Backlog milestone on Apr 7, 2017
SethTisue

SethTisue commented on May 16, 2023

@SethTisue
Member

not fixed in Scala 3 (3.3.0-RC6)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @SethTisue@scabug

        Issue actions

          soundness issue with path-dependent type on `null` path · Issue #9633 · scala/bug