Aladdin - Scala Bugtracking
[#1270] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Philipp Burak fixed 2007-08-08 15:20:54.0
subject Guard in PartialFunction with unapply crashes compiler
code
package test

object unapply13 extends Application {

  class Sync {
    def apply(x: Int): Int = 42
    def unapply(scrut: Any): Option[Int] = None
  }

  class Buffer {
    object Get extends Sync

    var ps: PartialFunction[Any, Any] = {
      case Get(y) if y > 4 =>
    }
  }

  println((new Buffer).ps.isDefinedAt(42))
}
what happened
Exception in thread "main" java.lang.Error: Unknown type: ?
        at scala.tools.nsc.Global.abort(Global.scala:164)
        at scala.tools.nsc.backend.icode.TypeKinds$class.toTypeKind(TypeKinds.scala:438)
        at scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:20)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:398)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genStat(GenICode.scala:179)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$1.apply(GenICode.scala:142)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$1.apply(GenICode.scala:141)
        at scala.List.foreach(List.scala:712)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genStat(GenICode.scala:141)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:947)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$\
genLoad(GenICode.scala:442)
        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)

The problem seems to be inside the isDefinedAt method where a local variable has type ? instead of int (after ex\
plicitouter):

final def isDefinedAt(x$1: Any): Boolean = {
             val temp5: Any = x$1;
             val temp6: Option[Int] = $anonfun.this.test$unapply13$Buffer$$anonfun$$$outer().Get().un\
apply(temp5);
            if (temp6.isEmpty().unary_!())
              {
                 val temp7: Int = temp6.get();
-->             val y: ? = temp7;
                if (y.>(4))
                  true
                else
                  false
              }
            else
              false
          };

However the equivalent variable has correct type int in the corresponding apply method.
what expected Compile without error.
[back to overview]
Changes of this bug report
Burak  edited on  2007-08-14 18:01:29.0