Aladdin - Scala Bugtracking
[#1060] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Nikolay Iulian fixed 2007-04-20 11:06:22.0
subject [contrib #437] Exception in thread "main" scala.MatchError: UNIT
code
The following code generates an exception:

object Test extends Application
{
  "fff".asInstanceOf[int]
}


Exception in thread "main" scala.MatchError: UNIT
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$41.apply(GenJVM.scala:822)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$41.apply(GenJVM.scala:655)
        at scala.Iterator$class.foreach(Iterator.scala:380)
        at scala.runtime.BoxedArray$$anon$0.foreach(BoxedArray.scala:42)
        at scala.Iterable$class.foreach(Iterable.scala:197)
        at scala.runtime.BoxedArray.foreach(BoxedArray.scala:21)
        at scala.tools.nsc.backend.icode.BasicBlocks$BasicBlock.traverse(BasicBlocks.scala:91)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlock(GenJVM.scala:655)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlocks(GenJVM.scala:576)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genCode(GenJVM.scala:566)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genMethod(GenJVM.scala:451)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$6.apply(GenJVM.scala:198)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$6.apply(GenJVM.scala:198)
        at scala.List.foreach(List.scala:702)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.scala:198)
        at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$0.apply(GenJVM.scala:44)
        at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$0.apply(GenJVM.scala:44)
        at scala.Iterator$class.foreach(Iterator.scala:380)
        at scala.collection.Map$$anon$2.foreach(Map.scala:111)
        at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:44)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:488)
        at scala.tools.nsc.Global$Run.compile(Global.scala:562)
        at scala.tools.nsc.Main$.process(Main.scala:57)
        at scala.tools.nsc.Main$.main(Main.scala:79)
        at scala.tools.nsc.Main.main(Main.scala)
what happened
what expected
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-04-20 11:35:42.0
contribution #437. I assigned to Iuli to fix the exception but I think this should be reported as an error by the compiler because we know statically that it will fail at runtime. Also, isInstanceOf for similar situations should yield a warning. BTW, Erasure generates incorrect code - scala.Int.unbox("fff")!
Iulian  edited on  2007-04-20 16:38:31.0
Fixed the code generator so it doesn't crash. The runtime behavior is correct, IMO (ClassCastException with java.lang.String).