@@ -913,7 +913,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
913
913
def outerSelect (levels : Int , tp : Type )(implicit ctx : Context ): Tree =
914
914
untpd.Select (tree, OuterSelectName (EmptyTermName , levels)).withType(SkolemType (tp))
915
915
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)
917
921
918
922
// --- Higher order traversal methods -------------------------------
919
923
@@ -942,7 +946,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
942
946
}
943
947
944
948
/** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
945
- object mapToUnderlying extends TreeMap {
949
+ object mapToUnderlyingArgument extends TreeMap {
946
950
override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
947
951
case tree : Ident if tree.symbol.is(InlineProxy ) || (tree.symbol.is(Synthetic ) && ! tree.symbol.owner.isClass) =>
948
952
tree.symbol.defTree match {
@@ -955,6 +959,23 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
955
959
}
956
960
}
957
961
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
+
958
979
implicit class ListOfTreeDecorator (val xs : List [tpd.Tree ]) extends AnyVal {
959
980
def tpes : List [Type ] = xs map (_.tpe)
960
981
}
0 commit comments