Compiler bug? java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to java.lang.Integer

StackOverflow https://stackoverflow.com/questions/15752629

Question

Scratching my head over a weird runtime error:

// File: build.sbt
scalaVersion := "2.10.1"

// File: src/main/scala/bug/Bug.scala
package bug

class Foo(val args: Any*)
case class Bar(id: Int) extends Foo(id)

object Bug extends App {
  val msg = Bar(666)
  val id  = msg.id // boom!
}

If I run this with sbt run"

[error] (run-main) java.lang.ClassCastException: 
  scala.collection.mutable.WrappedArray$ofRef cannot be cast to java.lang.Integer
java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be 
  cast to java.lang.Integer
    at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source)
    at bug.Bar.id(Test.scala:4)
    at bug.Bug$delayedInit$body.apply(Test.scala:8)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
        ...

What the heck is this? This seems a new bug of Scala 2.10.1, because if I change to scalaVersion := "2.10.0", it runs without problem.

Any ideas of a work around? (E.g. magic compiler flag)

Was it helpful?

Solution

According to Jason Zaugg, this is SI-7436 and should be fixed in Scala 2.10.3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top