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

ClassCastException from nested, parameterized value classes #6337

Closed
scabug opened this issue Sep 7, 2012 · 6 comments
Closed

ClassCastException from nested, parameterized value classes #6337

scabug opened this issue Sep 7, 2012 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 7, 2012

Getting the value from nested, parameterized value classes throws ClassCastException at runtime.

object C {
  def main(args: Array[String]) {
    val x = new X(new XX(3))
    println(x.i.x + 9)
  }
}

class X[T](val i: XX[T]) extends AnyVal
class XX[T](val x: T) extends AnyVal
$ scalac C.scala
$ scala C
java.lang.ClassCastException: XX cannot be cast to java.lang.Integer
	at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source)
	at C$.main(C.scala:4)
	at C.main(C.scala)
@scabug
Copy link
Author

scabug commented Sep 7, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6337?orig=1
Reporter: @harrah
Affected Versions: 2.10.0-M7, 2.10.0
Other Milestones: 2.10.0
See #6385

@scabug
Copy link
Author

scabug commented Sep 7, 2012

@jsuereth said:
Martin - I'm bumping this to you, send back if you need.

@scabug
Copy link
Author

scabug commented Sep 13, 2012

@harrah said:
Note that this doesn't require a bare type parameter in XX.

object C {
  def main(args: Array[String]) {
    val x = new X(new XX(Some(3)))
    println(x.i.x.get + 9)
  }
}

class X[T](val i: XX[T]) extends AnyVal
class XX[T](val x: Option[T]) extends AnyVal

The error is:

java.lang.ClassCastException: XX cannot be cast to scala.Option

@scabug
Copy link
Author

scabug commented Sep 17, 2012

@harrah said:
A similar problem occurs with a nested universal trait:

object C {
  def main(args: Array[String]) {
    val x = X(XX(3))
    println(x.q.x.x + 9)
  }
}
trait Q extends Any {
   def x: Int
   def inc: XX
}
case class X(val x: Q) extends AnyVal {
   def q = X(x.inc)
}
case class XX(val x: Int) extends AnyVal with Q {
   def inc = XX(x + 1)
}
java.lang.ClassCastException: XX cannot be cast to java.lang.Integer
	at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source)
	at XX.inc(XX.scala:15)
	at X$.extension$q(XX.scala:13)
	at C$.main(XX.scala:4)
	at C.main(XX.scala)

@scabug
Copy link
Author

scabug commented Sep 17, 2012

@odersky said:
scala/scala#1325

@scabug
Copy link
Author

scabug commented Sep 17, 2012

@harrah said:
Nested value classes weren't required for this latest problem. See #6385.

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