Aladdin - Scala Bugtracking
[#159] project: compiler priority: high category: bug
submitter assigned to status date submitted
Burak Martin fixed 2003-09-30 11:57:32.0
subject backend crash on val _ = ...
code
object foo {

  // the problem seems to appear only 
  // if "val _" is in the body of a case 
  def cooked( ckd:StringBuffer ):Unit = 
    'a'.match {
      case '-' =>
        val _ = ckd.append( '_' );
      case 'v' =>
        val _ = ckd.append( '_' );
    }
  
}
what happened
Exception in thread "main" scalac.ApplicationError: unknown node: scalac.ast.Tree$ExtValDef(val _: java.lang.Str\
ingBuffer = ckd.append('_'))
	at scalac.Global.fail(Global.java:543)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:547)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:228)
	at scalac.backend.jvm.GenJVM.gen(GenJVM.java:191)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:224)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:448)
	at scalac.backend.jvm.GenJVM.gen(GenJVM.java:191)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:224)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:458)
	at scalac.backend.jvm.GenJVM.genCond(GenJVM.java:700)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:457)
	at scalac.backend.jvm.GenJVM.genLoad(GenJVM.java:228)
	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 silent run.
[back to overview]
Changes of this bug report
Burak  edited on  2003-09-30 11:58:35.0
Burak  edited on  2003-09-30 11:59:05.0
Michel  edited on  2003-09-30 13:39:57.0
This is not a bug in the backend, but in the parser IMO, because it doesn't add an empty block in one of the two cases. Here is a slightly modified example:
object foo {
  def f():Unit = {
    1.match {
      case 2 => val _ = 1;
      case 3 => val _ = 2;
      case 4 => val _ = 2;
    }
  }
}
and here is how it looks after parsing:
[[Trees after phase parse]]
// Scala source: bug_159.scala
object foo extends scala.Object() {
  def f(): Unit = 1.match({
      case 2 => {
        val _ = 1
      }
      case 3 => {
        val _ = 2
      }
      case 4 => {
        val _ = 2;
        {
          
        }
      }
    })
};
As you can see, only the last case is correct, because the implicit empty block representing "unit" has indeed been added. This implicit unit is, however, missing in the two other cases. If you feed this code again in the compiler, it complains.

For now, a work-around is to explicitely put "unit" values in the code, like that:

object foo {
  def f():Unit = {
    1.match {
      case 2 => val _ = 1; ()
      case 3 => val _ = 2; ()
      case 4 => val _ = 2; ()
    }
  }
}
Martin  edited on  2003-10-06 12:23:31.0