Aladdin - Scala Bugtracking
[#1030] project: compiler priority: low category: bug
submitter assigned to status date submitted
Adriaan Martin open 2007-03-29 01:01:41.0
subject boxing&erasure for arrays inconsistent?
code
scala> val line = "Smith, John"                                              
line: java.lang.String = Smith, John

scala> val Array(lname, fname) = line split ", "
what happened
(in 2.4.0)
scala.MatchError: [Ljava.lang.String;@b9371e
        at line22$object$.(:5)
        at line22$object$.()
        at RequestResult$line22$object$.(:3)
        at RequestResult$line22$object$.()
        at RequestResult$line22$object.result()
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at scala.tools.nsc.Interpreter$Request.loadAndRun(Interpreter.scala:562)
        at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:285)
        at scala.tools.nsc.InterpreterLoop.interpretStartingWith(InterpreterLoop.scala:211)
        at scala.tools.nsc.InterpreterLoop.command(InterpreterLoop.scala:198)
        at scala.tools.nsc.InterpreterLoop.repl(InterpreterLoop.scala:111)
        at scala.tools.nsc.InterpreterLoop.main(InterpreterLoop.scala:246)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:92)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
what expected no error Investigating some more:
scala> val a:Array[String]=line split ", "
a: scala.Array[java.lang.String] = [Ljava.lang.String;@2a5319
I think the run-time type should be a BoxedAnyArray since `x.isInstanceOf[Array[A]]' gets erased to `x instanceof BoxedArray'
[back to overview]
Changes of this bug report
Adriaan  edited on  2007-03-29 01:02:00.0
Adriaan  edited on  2007-03-29 01:02:22.0
Adriaan  edited on  2007-03-29 01:30:00.0
On further reflection, I think unapplySeq should be changed to: def unapplySeq[A](x: Array[A]): Option[Seq[A]] = Some(x) Then it works.
Adriaan  edited on  2007-03-29 18:24:35.0
Martin, I'd close this bug (I committed the change to Array), were it not for this somewhat surprising behaviour: passing an instance of Array[A] to something that expects an Any and then does instanceOf[Array[A]] does not work, the array is passed as a Java-native array, instead of being boxed whereas the isInstanceOf is erased to instanceof BoxedArray -- maybe x.instanceOf needs to be erased differently depending on whether x is expected to be boxed?
Martin  edited on  2007-04-17 16:28:39.0
reassigned to me.