Aladdin - Scala Bugtracking
[#1164] project: compiler priority: low category: bug
submitter assigned to status date submitted
Burak Martin _ 2007-06-04 00:48:30.0
subject gen.mkAsInstanceOf gets the erased type
code
 class Foo {
   case class Bar extends Foo

   def foo() = this match {
     case Bar() => println("bar")
   }
}
what happened
while typing vdef_untyped =  var temp8: Foo.this.Bar = temp5.asInstanceOf$erased[Foo.this.Bar]()
casted.tpe = Foo.this.Bar
(a) selector.tpe       = Foo
(b) pattern type(ntpe) = Foo.this.Bar
isSubType(a, b) = false
cast.type = Foo#Bar

exception when transforming def foo(): Unit = this match {
  case ()Foo.this.Bar() => scala.this.Predef.println("bar")
}
...
Exception in thread "main" scala.tools.nsc.symtab.Types$TypeError: type mismatch;
 found   : Foo#Bar
 required: Foo.this.Bar
        at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:268)
        at scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:277)
        at scala.tools.nsc.typechecker.Infer$Inferencer.typeError(Infer.scala:286)
        at scala.tools.nsc.typechecker.Infer$Inferencer.typeErrorTree(Infer.scala:292)
        at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:733)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2660)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2701)
        at scala.tools.nsc.typechecker.Typers$Typer.transformedOrTyped(Typers.scala:2748)
        at scala.tools.nsc.typechecker.Typers$Typer.typedValDef(Typers.scala:1083)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:2424)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2657)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2690)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher.toTree_refined(PatternMatchers.scala:1211)
...
what expected I inserted and checked in relevant output that appears when the exception is thrown. The problem is that the cast does not get the proper type. I could of course set the type manually, but I wonder why I should need to, whether I need to do it systematically and whether this hints at a more general problem regarding casts to dependent types. Maybe we need asInstanceOf$nonErased back?
[back to overview]
Changes of this bug report
Martin  edited on  2007-06-04 10:41:20.0
In what phase is this being typed?
Burak  edited on  2007-06-04 11:01:49.0
ah, it's phase.next ... which is erasure! But what exactly does this mean for typing tree nodes during ExplicitOuter? Shall I just type the cast at phase.prev?