question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unsoundness due to `erased`

See original GitHub issue

Related to #50 #4042 #4031.

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

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

    object O { lazy val x : Y & 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)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Jul 4, 2018

Unfortunately, this makes erased vals practically useless. We should backout this fix and mark erased vals as unrealizable instead. erased is really the same as lazy in this respect. Either implies that the right-hand side will be constructed.

1reaction
Blaisorbladecommented, Mar 2, 2018

@alexknvl I renamed unused to ghost throughout the issue because of #4061.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[TYPES] Java generics unsoundness?
To avoid the method clash we could use name mangling, i.e., including the types of the type-erased arguments in the name of the...
Read more >
Unsoundness in owning_ref : r/rust - Reddit
158 votes, 42 comments. 212K subscribers in the rust community. A place for all things related to the Rust programming language—an ...
Read more >
Erased Tapes on Instagram: “‪If you're down in Brighton for the‬ ...
405 Likes, 5 Comments - Erased Tapes (@erasedtapesrecords) on Instagram: “‪If you're down in Brighton for the @GreatEscapeFest this weekend,‬ ...
Read more >
How LGBTQ Victims Were Erased From Holocaust History | Time
"For the queer survivors of Nazi oppression, 1945 did not bring about any kind of liberation," argues scholar Andrea Carlo.
Read more >
Java and Scala's Type Systems are Unsound - Hacker News
It was unsound from the first version with respect to arrays. If B is a subtype of A, then Java allows you to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found