@@ -2,18 +2,33 @@ package dotty.tools
22package dotc
33package ast
44
5- import dotty .tools .dotc .transform .{ExplicitOuter , Erasure }
5+ import dotty .tools .dotc .transform .{Erasure , ExplicitOuter }
66import dotty .tools .dotc .typer .ProtoTypes .FunProtoTyped
77import transform .SymUtils ._
88import transform .TypeUtils ._
99import core ._
10- import util .Positions ._ , Types ._ , Contexts ._ , Constants ._ , Names ._ , Flags ._ , NameOps ._
11- import SymDenotations ._ , Symbols ._ , StdNames ._ , Annotations ._ , Trees ._ , Symbols ._
12- import Denotations ._ , Decorators ._ , DenotTransformers ._
10+ import util .Positions ._
11+ import Types ._
12+ import Contexts ._
13+ import Constants ._
14+ import Names ._
15+ import Flags ._
16+ import NameOps ._
17+ import SymDenotations ._
18+ import Symbols ._
19+ import StdNames ._
20+ import Annotations ._
21+ import Trees ._
22+ import Symbols ._
23+ import Denotations ._
24+ import Decorators ._
25+ import DenotTransformers ._
26+
1327import collection .mutable
14- import util .{Property , SourceFile , NoSource }
28+ import util .{NoSource , Property , SourceFile }
1529import typer .ErrorReporting ._
16- import NameKinds .{TempResultName , OuterSelectName }
30+ import NameKinds .{OuterSelectName , TempResultName }
31+ import dotty .tools .dotc .ast .tpd .mapToUnderlying .transform
1732
1833import scala .annotation .tailrec
1934import scala .io .Codec
@@ -914,7 +929,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
914929 def outerSelect (levels : Int , tp : Type )(implicit ctx : Context ): Tree =
915930 untpd.Select (tree, OuterSelectName (EmptyTermName , levels)).withType(SkolemType (tp))
916931
917- def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
932+ /** Replace Inlined nodes and InlineProxy references to underlying arguments */
933+ def underlyingArgument (implicit ctx : Context ): Tree = mapToUnderlyingArgument.transform(tree)
934+
935+ /** Replace Ident nodes references to the underlying tree that defined them */
936+ def underlying (implicit ctx : Context ): Tree = mapToUnderlying.transform(tree)
918937
919938 // --- Higher order traversal methods -------------------------------
920939
@@ -943,15 +962,29 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
943962 }
944963
945964 /** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
946- object mapToUnderlying extends TreeMap {
965+ object mapToUnderlyingArgument extends TreeMap {
947966 override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
948967 case tree : Ident if tree.symbol.is(InlineProxy ) || (tree.symbol.is(Synthetic ) && ! tree.symbol.owner.isClass) =>
968+ transform(tree.symbol.defTree.asInstanceOf [ValOrDefDef ].rhs)
969+ case Inlined (_, _, arg) => transform(arg)
970+ case NamedArg (_, arg) => transform(arg)
971+ case tree => super .transform(tree)
972+ }
973+ }
974+
975+ /** Map Ident nodes references to underlying tree that defined them.
976+ * Also drops Inline and Block with no statements
977+ */
978+ object mapToUnderlying extends TreeMap {
979+ override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
980+ case tree : Ident if ! tree.symbol.owner.isClass =>
949981 tree.symbol.defTree match {
950982 case defTree : ValOrDefDef => transform(defTree.rhs)
951983 case _ => tree
952984 }
953985 case Inlined (_, _, arg) => transform(arg)
954986 case NamedArg (_, arg) => transform(arg)
987+ case Block (Nil , arg) => transform(arg)
955988 case tree => super .transform(tree)
956989 }
957990 }
0 commit comments