@@ -914,7 +914,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
914914 def outerSelect (levels : Int , tp : Type )(implicit ctx : Context ): Tree =
915915 untpd.Select (tree, OuterSelectName (EmptyTermName , levels)).withType(SkolemType (tp))
916916
917- def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
917+ /** Replace Inlined nodes and InlineProxy references to underlying arguments */
918+ def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlyingArgument.transform(tree)
919+
920+ /** Replace Ident nodes references to the underlying tree that defined them */
921+ def underlying (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
918922
919923 // --- Higher order traversal methods -------------------------------
920924
@@ -943,12 +947,31 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
943947 }
944948
945949 /** Map Inlined nodes and InlineProxy references to underlying arguments */
946- object mapToUnderlying extends TreeMap {
950+ object mapToUnderlyingArgument extends TreeMap {
947951 override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
948952 case tree : Ident if tree.symbol.is(InlineProxy ) =>
949- tree.symbol.defTree.asInstanceOf [ValOrDefDef ].rhs.underlyingArgument
953+ transform(tree.symbol.defTree.asInstanceOf [ValOrDefDef ].rhs)
954+ case Inlined (_, _, arg) =>
955+ transform(arg)
956+ case tree =>
957+ super .transform(tree)
958+ }
959+ }
960+
961+ /** Map Ident nodes references to underlying tree that defined them.
962+ * Also drops Inline and Block with no statements
963+ */
964+ object mapToUnderlying extends TreeMap {
965+ override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
966+ case tree : Ident if ! tree.symbol.owner.isClass =>
967+ tree.symbol.defTree match {
968+ case defTree : ValOrDefDef => transform(defTree.rhs)
969+ case _ => tree
970+ }
950971 case Inlined (_, _, arg) =>
951- arg.underlyingArgument
972+ transform(arg)
973+ case Block (Nil , arg) =>
974+ transform(arg)
952975 case tree =>
953976 super .transform(tree)
954977 }
0 commit comments