@@ -913,7 +913,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
913913 def outerSelect (levels : Int , tp : Type )(implicit ctx : Context ): Tree =
914914 untpd.Select (tree, OuterSelectName (EmptyTermName , levels)).withType(SkolemType (tp))
915915
916- def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
916+ /** Replace Inlined nodes and InlineProxy references to underlying arguments */
917+ def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlyingArgument.transform(tree)
918+
919+ /** Replace Ident nodes references to the underlying tree that defined them */
920+ def underlying (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
917921
918922 // --- Higher order traversal methods -------------------------------
919923
@@ -942,7 +946,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
942946 }
943947
944948 /** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
945- object mapToUnderlying extends TreeMap {
949+ object mapToUnderlyingArgument extends TreeMap {
946950 override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
947951 case tree : Ident if tree.symbol.is(InlineProxy ) || (tree.symbol.is(Synthetic ) && ! tree.symbol.owner.isClass) =>
948952 tree.symbol.defTree match {
@@ -955,6 +959,23 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
955959 }
956960 }
957961
962+ /** Map Ident nodes references to underlying tree that defined them.
963+ * Also drops Inline and Block with no statements
964+ */
965+ object mapToUnderlying extends TreeMap {
966+ override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
967+ case tree : Ident if ! tree.symbol.owner.isClass =>
968+ tree.symbol.defTree match {
969+ case defTree : ValOrDefDef => transform(defTree.rhs)
970+ case _ => tree
971+ }
972+ case Inlined (_, _, arg) => transform(arg)
973+ case Block (Nil , arg) => transform(arg)
974+ case NamedArg (_, arg) => transform(arg)
975+ case tree => super .transform(tree)
976+ }
977+ }
978+
958979 implicit class ListOfTreeDecorator (val xs : List [tpd.Tree ]) extends AnyVal {
959980 def tpes : List [Type ] = xs map (_.tpe)
960981 }
0 commit comments