From 71b900fde4cb5937c1cbb19da6e3397586e2467c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 13 Dec 2016 14:56:00 +0100 Subject: Ref copier that works for Idents and Selects The Ref copier copies Idents and Selects, changing the name of either. --- compiler/src/dotty/tools/dotc/ast/Trees.scala | 5 +++++ compiler/src/dotty/tools/dotc/ast/tpd.scala | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'compiler/src/dotty') diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 20273eb85..5e2fb99bf 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -890,6 +890,11 @@ object Trees { case tree: Select if (qualifier eq tree.qualifier) && (name == tree.name) => tree case _ => finalize(tree, untpd.Select(qualifier, name)) } + /** Copy Ident or Select trees */ + def Ref(tree: RefTree)(name: Name)(implicit ctx: Context) = tree match { + case Ident(_) => Ident(tree)(name) + case Select(qual, _) => Select(tree)(qual, name) + } def This(tree: Tree)(qual: untpd.Ident): This = tree match { case tree: This if qual eq tree.qual => tree case _ => finalize(tree, untpd.This(qual)) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index cd6b3fcf2..433808e8e 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -450,7 +450,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { } else foldOver(sym, tree) } - override val cpy = new TypedTreeCopier + override val cpy: TypedTreeCopier = // Type ascription needed to pick up any new members in TreeCopier (currently there are none) + new TypedTreeCopier class TypedTreeCopier extends TreeCopier { def postProcess(tree: Tree, copied: untpd.Tree): copied.ThisTree[Type] = -- cgit v1.2.3