Skip to content
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

rather spectacular soundness failure with abstract types #5120

Closed
scabug opened this issue Oct 27, 2011 · 2 comments
Closed

rather spectacular soundness failure with abstract types #5120

scabug opened this issue Oct 27, 2011 · 2 comments

Comments

@scabug
Copy link

scabug commented Oct 27, 2011

This is in all versions of scala, it's not a regression or anything.

class Cell[T](x0: T) {
  type U = T
  var x1: U = x0
}

object Test {
  val str: Cell[String] = new Cell("a")
  val other: Cell[Int]  = new Cell(0)
  
  def main(args: Array[String]): Unit = {
    List(str, other) foreach (_.x1 = new AnyRef)
    str.x1.length
  }
}
// java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
//	at Test$.main(a.scala:12)
//	at Test.main(a.scala)

The inferred lub of the list is List[Cell[_ >: Int with String]], which seems fine, except that this existential can't be simplified to "Any" because it leads directly back to the setter for x1. It's hard for me to see how an abstract type declared to be the same as a type parameter can be safely allowed fewer restrictions than the type parameter.

@scabug
Copy link
Author

scabug commented Oct 27, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5120?orig=1
Reporter: @paulp
See #5517

@scabug
Copy link
Author

scabug commented Nov 1, 2011

@odersky said:
Fixed in r25928.

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

No branches or pull requests

2 participants