Aladdin - Scala Bugtracking
[#351] project: compiler priority: high category: bug
submitter assigned to status date submitted
Burak Philippe fixed 2004-07-16 19:13:35.0
subject VerifyError on Array[A] where A abstract type member
code
abstract class Foo {
  type A = bar.A;
  val bar:Bar;

  bar.handleBaz(  new Array[A](0) );
}

abstract class Bar {
  type A;
  def handleBaz(arr:Array[A]) = 0;
}
object Test  with Application {
  new Foo {
    val bar = new Bar {
      type A = Int; // using some AnyRef also yields error
    }
  }
}
what happened
/tmp> /local/buraq/scala.fallback/scala/bin/scala Test
Exception in thread "main" java.lang.ExceptionInInitializerError
	at Test.main(foo.scala:45)
Caused by: java.lang.NullPointerException
	at Foo$class.(foo.scala:5)
	at Test$$anon$0.(foo.scala:14)
	at Test$.(foo.scala:14)
	at Test$.(foo.scala)
	... 1 more
This is the bytecode:
/tmp> javap -c Foo\$class
Compiled from "foo.scala"
public abstract class Foo$class extends java.lang.Object implements Foo{
public static {};
  Code:
   0:	return

public Foo$class();
  Code:
   0:	aload_0
   1:	invokespecial	#11; //Method java/lang/Object."":()V
   4:	aload_0
   5:	invokeinterface	#17,  1; //InterfaceMethod Foo.bar:()LBar;
   10:	iconst_0
   11:	anewarray	#9; //class Object
   14:	checkcast	#19; //class Object;"
   17:	invokestatic	#25; //Method scala/runtime/RunTime.box_oarray:([Ljava/lang/Object;)Lscala/Array;
   20:	invokeinterface	#31,  2; //InterfaceMethod Bar.handleBaz:(Lscala/Array;)I
   25:	pop
   26:	return
what expected hm, erase Array[A] to Array[Object] in call to Bar::handleBaz ?
[back to overview]
Changes of this bug report
Burak  edited on  2004-07-16 19:14:20.0
In absence of Michel, I assign this one to Philippe, maybe you can help, I am depending on this to work...
Philippe  edited on  2004-07-19 11:08:20.0
I don't see any VerifyError. There is only a NullPointerException because bar is access from Foo before it is initialized in the anonymous subclass. If you add to class an argument for the initial value of bar then everything is ok.
Burak  edited on  2004-07-19 12:03:46.0
I can reproduce this error, with the latest CVS as well as with the /home/linuxsoft version.
Philippe  edited on  2004-07-19 13:39:38.0
Indeed, the error can be reproduced, but as I explained that's the correct behaviour. The problem is that you access a non-initialized value in class Foo. Here is a shorter example which exhibits the same error.
abstract class Foo {
  val v: Any;
  System.out.println(v.toString());
}

object Test  with Application {
  new Foo {
    val v: Any = "initial-value-that-comes-to-late";
  }
}
When System.out.println(v.toString()); is executed, v is not yet initialized.