Skip to content

Unsoundness due to initialization-produced null #4042

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

Closed
sir-wabbit opened this issue Feb 26, 2018 · 2 comments · Fixed by #11716
Closed

Unsoundness due to initialization-produced null #4042

sir-wabbit opened this issue Feb 26, 2018 · 2 comments · Fixed by #11716

Comments

@sir-wabbit
Copy link

sir-wabbit commented Feb 26, 2018

Similar to #4031. Derived from this gist, which works in Scala2.

object App {
  def coerce[U, V](u: U): V = {
    trait X { type R >: U }
    trait Y { type R = V }

    class T[A <: X](val a: A)(val value: a.R)

    object O { val x : Y & X = x }

    val a = new T[Y & X](O.x)(u)
    a.value
  }

  def main(args: Array[String]): Unit = {
    val x: Int = coerce[String, Int]("a")
    println(x + 1)
  }
}

/////////////////////////////////

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:101)
	at App$.main(HelloWorld.scala:15)
	at App.main(HelloWorld.scala)

Tested on the most recent master branch.

@Blaisorblade Blaisorblade self-assigned this Feb 27, 2018
@Blaisorblade
Copy link
Contributor

Ok, finally found time to read it. I’m almost asleep, but I’m guessing that O.x ends up being null, assuming that’s right, we know null introduces unsoundness in Scala and Java (all versions) and null-tracking is not yet implemented, though we plan to get to it. I’ll figure out how to sort this snippet among “pending” testcases for null-tracking.

@Blaisorblade Blaisorblade changed the title Another unsoundness Another unsoundness due to initialization-produced null Feb 28, 2018
@Blaisorblade
Copy link
Contributor

Confirm that O.x is null.
So the issue is a duplicate of (the null-related part of) #50 (see #50 (comment) for the latest comment).

@Blaisorblade Blaisorblade changed the title Another unsoundness due to initialization-produced null Unsoundness due to initialization-produced null Mar 1, 2018
@Blaisorblade Blaisorblade removed their assignment Jul 1, 2020
@liufengyun liufengyun self-assigned this Mar 17, 2021
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 17, 2021
@liufengyun liufengyun linked a pull request Mar 17, 2021 that will close this issue
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 22, 2021
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment