@@ -919,7 +919,17 @@ 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 = {
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+ }
930+
931+ /** Replace Ident nodes references to the underlying tree that defined them */
932+ def underlying (implicit ctx : Context ): Tree = new MapToUnderlying ().transform(tree)
923933
924934 // --- Higher order traversal methods -------------------------------
925935
@@ -947,18 +957,22 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
947957 }
948958 }
949959
950- /** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
951- object mapToUnderlying extends TreeMap {
960+ /** Map Inlined nodes, NamedArgs, Blocks with no statements and local references to underlying arguments.
961+ * Also drops Inline and Block with no statements.
962+ */
963+ class MapToUnderlying extends TreeMap {
952964 override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
953- case tree : Ident if tree.symbol.is( InlineProxy ) || (tree.symbol.is( Synthetic ) && ! tree.symbol.owner.isClass ) =>
965+ case tree : Ident if ! tree.symbol.owner.isClass && skipLocal( tree.symbol) =>
954966 tree.symbol.defTree match {
955967 case defTree : ValOrDefDef => transform(defTree.rhs)
956968 case _ => tree
957969 }
958970 case Inlined (_, _, arg) => transform(arg)
971+ case Block (Nil , arg) => transform(arg)
959972 case NamedArg (_, arg) => transform(arg)
960973 case tree => super .transform(tree)
961974 }
975+ def skipLocal (sym : Symbol ): Boolean = true
962976 }
963977
964978 implicit class ListOfTreeDecorator (val xs : List [tpd.Tree ]) extends AnyVal {
0 commit comments