Aladdin - Scala Bugtracking
[#627] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Burak Martin fixed 2006-06-16 00:03:53.0
subject casting array[int] to seq[int] fails
code
object Foo {
  def main(args:Array[String]): Unit = {
    Array(1,2,3,4).asInstanceOf[Seq[Int]].length
  }
}
what happened
Burak-Emirs-MacBook-Pro:~/Documents/svn/scala buraq$ java -classpath /tmp:build/quick/lib/library Foo
Exception in thread "main" java.lang.ClassCastException: [I
        at Foo$.main(test2.scala:3)
        at Foo.main(test2.scala)
what expected clearly, Array[A] extends Seq[A]. Of course scala.Array does not really exist, but it is still annoying that one can write programs that explode for no logical reason.
[back to overview]
Changes of this bug report
Burak  edited on  2006-06-16 00:06:53.0
Another example where this is annoying is the following (will generate same runtime error)
object Foo {
  def main(args:Array[String]): Unit = {
    Array(1,2,3,4) match {
      case Seq(xs@_*) => xs.length
    }
  }
}
Martin  edited on  2006-06-17 12:34:27.0
Burak  edited on  2006-06-19 05:54:14.0
I fixed pattern matching, so the example in my comment does not fail anymore.