I was checking out a tutorial, found at
http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-4
This tutorial is from jan. 2008, I see, but I’m using Scala 2.8.0 if that makes a difference.
class Color(val red:Int, val green:Int, val blue:Int)
case class Red(r:Int) extends Color(r, 0, 0)
case class Green(g:Int) extends Color(0, g, 0)
case class Blue(b:Int) extends Color(0, 0, b)
def printColor(c:Color) = c match {
case Red(v) => println("Red: " + v)
case Green(v) => println("Green: " + v)
case Blue(v) => println("Blue: " + v)
case col:Color => {
print("R: " + col.red + ", ")
print("G: " + col.green + ", ")
println("B: " + col.blue)
}
case null => println("Invalid color")
}
When entering this into the interpreter, it produces
Exception in thread “main” java.lang.IndexOutOfBoundsException
at scala.collection.LinearSeqOptimized$class.apply(LinearSeqOptimized.scala:53)
at scala.collection.immutable.List.apply(List.scala:45)
plus another 185 lines of tracing, and the interpreter exits.
What does this error message mean, and can anyone tell me what is wrong with the code above?
A message like that is always a bug. Specifically https://lampsvn.epfl.ch/trac/scala/ticket/4025 .