Skip to content

Commit

Permalink
SI-6023 reify abstract vals
Browse files Browse the repository at this point in the history
Type trees created by MethodSynthesis for abstract val getters carry symless originals,
which are unusable for reification purposes
(or the result of reification will be unhygienic).

To combat this, type trees for such getters are now created empty,
i.e. without any `tpe` set, just having an original assigned.
Subsequent `typedTypeTree` invocations fill in the `tpe` and
update the original to be symful.
  • Loading branch information
martende authored and xeno-by committed Nov 23, 2012
1 parent a0e642b commit 548a54d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Expand Up @@ -426,6 +426,7 @@ trait MethodSynthesis {
// spot that brand of them. In other words it's an artifact of the implementation.
val tpt = derivedSym.tpe.finalResultType match {
case ExistentialType(_, _) => TypeTree()
case _ if mods.isDeferred => TypeTree()
case tp => TypeTree(tp)
}
tpt setPos derivedSym.pos.focus
Expand Down
10 changes: 8 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -5368,8 +5368,14 @@ trait Typers extends Modes with Adaptations with Tags {
}

def typedTypeTree(tree: TypeTree) = {
if (tree.original != null)
tree setType typedType(tree.original, mode).tpe
if (tree.original != null) {
val newTpt = typedType(tree.original, mode)
tree setType newTpt.tpe
newTpt match {
case tt @ TypeTree() => tree setOriginal tt.original
case _ => tree
}
}
else
// we should get here only when something before failed
// and we try again (@see tryTypedApply). In that case we can assign
Expand Down
12 changes: 12 additions & 0 deletions test/files/run/t6023.check
@@ -0,0 +1,12 @@
{
abstract trait Foo extends AnyRef {
<stable> <accessor> def a: Int
};
()
}
{
abstract trait Foo extends AnyRef {
<stable> <accessor> def a: Int
};
()
}
17 changes: 17 additions & 0 deletions test/files/run/t6023.scala
@@ -0,0 +1,17 @@
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => cm}
import scala.tools.reflect.ToolBox

object Test extends App {
// test 1: reify
val tree = reify{ trait Foo { val a: Int } }.tree
println(tree.toString)

// test 2: import and typecheck
val toolbox = cm.mkToolBox()
val ttree = toolbox.typeCheck(tree)
println(ttree.toString)

// test 3: import and compile
toolbox.eval(tree)
}

0 comments on commit 548a54d

Please sign in to comment.