diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/reflect/internal/Trees.scala | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/compiler/scala/reflect/internal/Trees.scala b/src/compiler/scala/reflect/internal/Trees.scala index 5ef7ee3a27..91492f973a 100644 --- a/src/compiler/scala/reflect/internal/Trees.scala +++ b/src/compiler/scala/reflect/internal/Trees.scala @@ -348,10 +348,16 @@ trait Trees extends api.Trees { self: SymbolTable => override def toString = substituterString("Symbol", "Tree", from, to) } + /** Substitute clazz.this with `to`. `to` must be an attributed tree. + */ class ThisSubstituter(clazz: Symbol, to: => Tree) extends Transformer { - override def transform(tree: Tree) = tree match { - case This(_) if tree.symbol == clazz => to - case _ => super.transform(tree) + val newtpe = to.tpe + override def transform(tree: Tree) = { + if (tree.tpe ne null) tree.tpe = tree.tpe.substThis(clazz, newtpe) + tree match { + case This(_) if tree.symbol == clazz => to + case _ => super.transform(tree) + } } } |