@@ -919,7 +919,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
919919 def outerSelect (levels : Int , tp : Type )(implicit ctx : Context ): Tree =
920920 untpd.Select (tree, OuterSelectName (EmptyTermName , levels)).withType(SkolemType (tp))
921921
922- def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
922+ /** Replace Inlined nodes and InlineProxy references to underlying arguments */
923+ def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlyingArgument.transform(tree)
924+
925+ /** Replace Ident nodes references to the underlying tree that defined them */
926+ def underlying (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
923927
924928 // --- Higher order traversal methods -------------------------------
925929
@@ -948,7 +952,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
948952 }
949953
950954 /** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
951- object mapToUnderlying extends TreeMap {
955+ object mapToUnderlyingArgument extends TreeMap {
952956 override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
953957 case tree : Ident if tree.symbol.is(InlineProxy ) || (tree.symbol.is(Synthetic ) && ! tree.symbol.owner.isClass) =>
954958 tree.symbol.defTree match {
@@ -961,6 +965,23 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
961965 }
962966 }
963967
968+ /** Map Ident nodes references to underlying tree that defined them.
969+ * Also drops Inline and Block with no statements
970+ */
971+ object mapToUnderlying extends TreeMap {
972+ override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
973+ case tree : Ident if ! tree.symbol.owner.isClass =>
974+ tree.symbol.defTree match {
975+ case defTree : ValOrDefDef => transform(defTree.rhs)
976+ case _ => tree
977+ }
978+ case Inlined (_, _, arg) => transform(arg)
979+ case Block (Nil , arg) => transform(arg)
980+ case NamedArg (_, arg) => transform(arg)
981+ case tree => super .transform(tree)
982+ }
983+ }
984+
964985 implicit class ListOfTreeDecorator (val xs : List [tpd.Tree ]) extends AnyVal {
965986 def tpes : List [Type ] = xs map (_.tpe)
966987 }
0 commit comments