Skip to content

Commit d4f257d

Browse files
committed
Ref copier that works for Idents and Selects
The Ref copier copies Idents and Selects, changing the name of either.
1 parent a9006c5 commit d4f257d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,11 @@ object Trees {
890890
case tree: Select if (qualifier eq tree.qualifier) && (name == tree.name) => tree
891891
case _ => finalize(tree, untpd.Select(qualifier, name))
892892
}
893+
/** Copy Ident or Select trees */
894+
def Ref(tree: RefTree)(name: Name)(implicit ctx: Context) = tree match {
895+
case Ident(_) => Ident(tree)(name)
896+
case Select(qual, _) => Select(tree)(qual, name)
897+
}
893898
def This(tree: Tree)(qual: untpd.Ident): This = tree match {
894899
case tree: This if qual eq tree.qual => tree
895900
case _ => finalize(tree, untpd.This(qual))

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
450450
} else foldOver(sym, tree)
451451
}
452452

453-
override val cpy = new TypedTreeCopier
453+
override val cpy: TypedTreeCopier = // Type ascription needed to pick up any new members in TreeCopier (currently there are none)
454+
new TypedTreeCopier
454455

455456
class TypedTreeCopier extends TreeCopier {
456457
def postProcess(tree: Tree, copied: untpd.Tree): copied.ThisTree[Type] =

0 commit comments

Comments
 (0)