Skip to content

Commit 82b6f95

Browse files
committed
Factor out common MapToUnderlyingXYZ code
1 parent ccff48e commit 82b6f95

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,16 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
920920
untpd.Select(tree, OuterSelectName(EmptyTermName, levels)).withType(SkolemType(tp))
921921

922922
/** Replace Inlined nodes and InlineProxy references to underlying arguments */
923-
def underlyingArgument(implicit ctx: Context): Tree = mapToUnderlyingArgument.transform(tree)
923+
def underlyingArgument(implicit ctx: Context): Tree = {
924+
val mapToUnderlying = new MapToUnderlying {
925+
override def skipLocal(sym: Symbol): Boolean =
926+
sym.is(InlineProxy) || sym.is(Synthetic)
927+
}
928+
mapToUnderlying.transform(tree)
929+
}
924930

925931
/** Replace Ident nodes references to the underlying tree that defined them */
926-
def underlying(implicit ctx: Context): Tree = mapToUnderlying.transform(tree)
932+
def underlying(implicit ctx: Context): Tree = new MapToUnderlying().transform(tree)
927933

928934
// --- Higher order traversal methods -------------------------------
929935

@@ -951,26 +957,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
951957
}
952958
}
953959

954-
/** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
955-
object mapToUnderlyingArgument extends TreeMap {
956-
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
957-
case tree: Ident if tree.symbol.is(InlineProxy) || (tree.symbol.is(Synthetic) && !tree.symbol.owner.isClass) =>
958-
tree.symbol.defTree match {
959-
case defTree: ValOrDefDef => transform(defTree.rhs)
960-
case _ => tree
961-
}
962-
case Inlined(_, _, arg) => transform(arg)
963-
case NamedArg(_, arg) => transform(arg)
964-
case tree => super.transform(tree)
965-
}
966-
}
967-
968-
/** Map Ident nodes references to underlying tree that defined them.
969-
* Also drops Inline and Block with no statements
960+
/** Map Inlined nodes, NamedArgs, Blocks with no statements and local references to underlying arguments.
961+
* Also drops Inline and Block with no statements.
970962
*/
971-
object mapToUnderlying extends TreeMap {
963+
class MapToUnderlying extends TreeMap {
972964
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
973-
case tree: Ident if !tree.symbol.owner.isClass =>
965+
case tree: Ident if !tree.symbol.owner.isClass && skipLocal(tree.symbol) =>
974966
tree.symbol.defTree match {
975967
case defTree: ValOrDefDef => transform(defTree.rhs)
976968
case _ => tree
@@ -980,6 +972,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
980972
case NamedArg(_, arg) => transform(arg)
981973
case tree => super.transform(tree)
982974
}
975+
def skipLocal(sym: Symbol): Boolean = true
983976
}
984977

985978
implicit class ListOfTreeDecorator(val xs: List[tpd.Tree]) extends AnyVal {

0 commit comments

Comments
 (0)