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 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

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 7, 2012

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

@scabug

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 17, 2012

@scabug

This comment has been minimized.

Copy link
Author

@scabug 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.