Aladdin - Scala Bugtracking
[#917] project: compiler priority: low category: bug
submitter assigned to status date submitted
Nikolay Burak fixed 2007-01-28 23:06:41.0
subject [contrib #313] compiler crash (pattern matching)
code
object Box {                              
  def unapply(x: String): Option[String] = {
  	if (x == "something") Some("yes") else None
  }
}

object BoxTest extends Application {
  val obj: String = "anything" 
  obj match { 
  	case Box(n) => Console.println(n) 
  }
}
what happened
Compiler crashed with the following trace:
>scalac testi3.scala
exception when typing Box.unapply()  ("anything")
exception when typing private  val obj: java.lang.String = Box.unapply()  ("anything")
exception when typing final class BoxTest extends java.lang.Object with scala.Ap
plication with scala.ScalaObject {
  def this(): object BoxTest = {
    BoxTest.super.this();
    BoxTest.this./*Application$class*/$init$();
    ()
  };
  private  val obj: java.lang.String = Box.unapply()  ("anything");
    def obj(): java.lang.String = BoxTest.this.obj;
  {
     var temp0: java.lang.String = BoxTest.this.obj();
    {
       var temp2: scala.Option = Box.unapply(temp0);
      temp2.isEmpty().!().&&({
        exit(scala.Console.println(temp2.get()));
        true
      })
    };
    throw new scala.MatchError(temp0);
    exit(result){
      result
    }
  }
}
exception when typing package  {
  final class Box extends java.lang.Object with scala.ScalaObject {
    def this(): object Box = {
      Box.super.this();
      ()
    };
    def unapply(x: java.lang.String): scala.Option = if (x.==("something"))
      new scala.Some("yes")
    else
      scala.None
  };
  final class BoxTest extends java.lang.Object with scala.Application with scala
.ScalaObject {
    def this(): object BoxTest = {
      BoxTest.super.this();
      BoxTest.this./*Application$class*/$init$();
      ()
    };
    private  val obj: java.lang.String = Box.unapply()
 ("anything");
      def obj(): java.lang.String = BoxTest.this.obj;
    {
       var temp0: java.lang.String = BoxTest.this.obj();
      {
         var temp2: scala.Option = Box.unapply(temp0);
        temp2.isEmpty().!().&&({
          exit(scala.Console.println(temp2.get()));
          true
        })
      };
      throw new scala.MatchError(temp0);
      exit(result){
        result
      }
    }
  }
}
Exception in thread "main" java.lang.Error: unexpected tree: Box.unapply()  ("anything")
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:2212)
        at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2276)
        at scala.tools.nsc.typechecker.Typers$Typer.transformedOrTyped(Typers.sc
ala:2315)
        at scala.tools.nsc.typechecker.Typers$Typer.typedValDef(Typers.scala:942
)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1845)
        at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2265)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:129
6)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.sca
la:1317)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.sca
la:1317)
        at scala.List$.loop$0(List.scala:243)
        at scala.List$.mapConserve(List.scala:260)
        at scala.List$.loop$0(List.scala:247)
        at scala.List$.mapConserve(List.scala:260)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:1317
)
        at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:9
20)
        at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:8
25)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1839)
        at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2265)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:129
6)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.sca
la:1317)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.sca
la:1317)
        at scala.List$.loop$0(List.scala:243)
        at scala.List$.mapConserve(List.scala:260)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:1317
)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1835)
        at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2265)
        at scala.tools.nsc.transform.Erasure$ErasureTransformer$$anonfun$26.appl
y(Erasure.scala:826)
        at scala.tools.nsc.transform.Erasure$ErasureTransformer$$anonfun$26.appl
y(Erasure.scala:823)
        at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:77)
        at scala.tools.nsc.transform.Erasure$ErasureTransformer.transform(Erasur
e.scala:823)
        at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:1212)

        at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:230)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:219)

        at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:219)

        at scala.Iterator$class.foreach(Iterator.scala:377)
        at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:
244)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:219)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:484)
        at scala.tools.nsc.Global$Run.compile(Global.scala:555)
        at scala.tools.nsc.Main$.process(Main.scala:59)
        at scala.tools.nsc.Main$.main(Main.scala:81)
        at scala.tools.nsc.Main.main(Main.scala)
what expected No crash.
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-01-28 23:07:10.0
contribution #313
Burak  edited on  2007-03-03 03:01:50.0
Burak  edited on  2007-03-03 03:03:38.0
seems to be fixed, magically.
Burak  edited on  2007-07-06 11:43:58.0
this thing gives a match error, as it should.