Aladdin - Scala Bugtracking
[#1257] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Philipp Burak fixed 2007-08-07 17:04:46.0
subject Nested object with unapply crashes compiler
code
package test

object unapplyJoins extends Application {

  class Sync {
    def apply(): Int = 42
    def unapply(scrut: Any): Boolean = false
  }

  class Buffer {
    object Get extends Sync

    val jp: PartialFunction[Any, Any] = {
      case Get() =>
    }
  }

  println((new Buffer).jp.isDefinedAt(42))
}
what happened
Compiler crash:

Exception in thread "main" java.lang.AssertionError: assertion failed: Trying to access the this of another clas\
s: tree.symbol = class unapplyJoins$Buffer, ctx.clazz.symbol = class unapplyJoins$Buffer$$anonfun$0 compilation \
unit:stripped5.scala
        at scala.Predef$.assert(Predef.scala:96)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:857)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1062)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:833)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1062)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:833)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genCond(GenICode.scala:1405)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:420)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:948)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:110)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:68)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:68)
        at scala.List.foreach(List.scala:712)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:68)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:132)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:86)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:68)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$0.apply(GenICode.scala:68)
        at scala.List.foreach(List.scala:712)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:68)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:78)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:64)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:60)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:258)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:247)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:247)
        at scala.Iterator$class.foreach(Iterator.scala:375)
        at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:255)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:247)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:53)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:543)
        at scala.tools.nsc.Global$Run.compile(Global.scala:624)
        at scala.tools.nsc.Main$.process(Main.scala:86)
        at scala.tools.nsc.Main$.main(Main.scala:107)
        at scala.tools.nsc.Main.main(Main.scala)

Here is part of the problem (code after cleanup):

final def isDefinedAt(x$1: java.lang.Object): Boolean = if (unapplyJoins$Buffer.this.Get().unapply(x$1))
      true
    else
      false;

The selection of Get is wrong since the enclosing class is unapplyJoins$Buffer$$anonfun$0 and not unapplyJoins$B\
uffer.
what expected Compilation without errors.
[back to overview]
Changes of this bug report
Burak  edited on  2007-08-08 13:09:23.0
it was a missing handleOuter call in the pattern matching translation (which is interlocked with explicitouter). Generally speaking, we really need some diagnostic mechanism for this sort of problems, they seem rather easy to detect. Maybe a 'paranoid mode' could prevent such code from making it all the way to the backend.
Burak  edited on  2007-08-08 13:09:31.0