Aladdin - Scala Bugtracking
[#121] project: compiler priority: high category: bug
submitter assigned to status date submitted
Matthias Philippe fixed 2003-09-10 15:43:53.0
subject Return and array access
code
class B(b: Array[Byte]) {
  def get(x: Int): Byte = return b(x);
}
what happened
Crashes the backend:
Exception in thread "main" scalac.ApplicationError:
  unknown node: scalac.ast.Tree$ExtReturn(return scala.runtime.RunTime.barray_get($B$b(), x))
        at scalac.Global.fail(Global.java:543)
        at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:541)
        at scalac.backend.jvm.GenJVM.genLoadQualifier(GenJVM.java:587)
        at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:249)
        at scalac.backend.jvm.GenJVM.genLoadQualifier(GenJVM.java:587)
        at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:376)
        at scalac.backend.jvm.GenJVM.gen(GenJVM.java:165)
        at scalac.backend.jvm.GenJVM.gen(GenJVM.java:199)
        at scalac.backend.jvm.GenJVM.gen(GenJVM.java:143)
        at scalac.backend.jvm.GenJVM.gen(GenJVM.java:138)
        at scalac.backend.jvm.GenJVM.translate(GenJVM.java:110)
        at scalac.backend.jvm.GenJVMPhase.apply(GenJVMPhase.java:45)
        at scalac.Global.compile(Global.java:293)
        at scalac.Global.compile(Global.java:266)
        at scalac.Main.main(Main.java:32)
what expected Compiles without crash.
[back to overview]
Changes of this bug report
Burak  edited on  2003-09-23 18:27:32.0
Michel  edited on  2003-09-29 16:39:46.0
This is in fact a bug in erasure, which tries to cast the result of the "return" expression, which has no result... Here is what I get if I print the tree before and after erasure, where double square brackets enclose the expression to be returned:
[[Trees after phase expandmixins]]
// Scala source: bug_121.scala
interface B() extends java.lang.Object() {
  def $B$b(): scala.Array[scala.Byte];
  def get(x: scala.Int): scala.Byte
};
class B$class(b: scala.Array[scala.Byte]) extends Object() with B() {
  private val b$: scala.Array[scala.Byte] = b;
  def $B$b(): scala.Array[scala.Byte] = b$;
  def get(x: scala.Int): scala.Byte = return [[$B$b().apply(x)]]
};

[[Trees after phase erasure]]
// Scala source: bug_121.scala
interface B() extends java.lang.Object() {
  def $B$b(): byte[];
  def get(x: int): byte
};
class B$class(b: byte[]) extends Object() with B() {
  private val b$: byte[] = b;
  def $B$b(): byte[] = b$;
  def get(x: int): byte = return [[scala.runtime.RunTime.barray_get($B$b(), x)]].asInstanceOf[scala.Double]().asByte()
};
Philippe  edited on  2003-09-29 17:37:02.0
Changed erasure to add a block around each return statement. The block contains the return statement followed by a null value.