@@ -971,7 +971,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
971
971
/** Replace Inlined nodes and InlineProxy references to underlying arguments */
972
972
def underlyingArgument (implicit ctx : Context ): Tree = {
973
973
val mapToUnderlying = new MapToUnderlying {
974
- override def skipLocal (sym : Symbol ): Boolean =
974
+ /** Should get the rhs of this binding
975
+ * Returns true if the symbol is a val or def generated by eta-expansion/inline
976
+ */
977
+ override protected def skipLocal (sym : Symbol ): Boolean =
975
978
sym.is(InlineProxy ) || sym.is(Synthetic )
976
979
}
977
980
mapToUnderlying.transform(tree)
@@ -1018,17 +1021,28 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
1018
1021
*/
1019
1022
class MapToUnderlying extends TreeMap {
1020
1023
override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
1021
- case tree : Ident if tree.symbol.exists && ! tree.symbol.owner.isClass && ! tree.symbol.isAnonymousFunction && skipLocal(tree.symbol) =>
1024
+ case tree : Ident if isBinding( tree.symbol) && skipLocal(tree.symbol) =>
1022
1025
tree.symbol.defTree match {
1023
- case defTree : ValOrDefDef if ! defTree.rhs.isEmpty => transform(defTree.rhs)
1026
+ case defTree : ValOrDefDef =>
1027
+ val rhs = defTree.rhs
1028
+ assert(! rhs.isEmpty)
1029
+ transform(rhs)
1024
1030
case _ => tree
1025
1031
}
1026
1032
case Inlined (_, _, arg) => transform(arg)
1027
1033
case Block (Nil , arg) => transform(arg)
1028
1034
case NamedArg (_, arg) => transform(arg)
1029
1035
case tree => super .transform(tree)
1030
1036
}
1031
- def skipLocal (sym : Symbol ): Boolean = true
1037
+
1038
+ /** Should get the rhs of this binding */
1039
+ protected def skipLocal (sym : Symbol ): Boolean = true
1040
+
1041
+ /** Is this a symbol that of a local val or parameterless def for which we could get the rhs */
1042
+ private def isBinding (sym : Symbol )(implicit ctx : Context ): Boolean = {
1043
+ sym.isTerm && ! sym.is(Param ) && ! sym.owner.isClass &&
1044
+ ! (sym.is(Method ) && sym.info.isInstanceOf [MethodOrPoly ]) // if is a method it is parameterless
1045
+ }
1032
1046
}
1033
1047
1034
1048
implicit class ListOfTreeDecorator (val xs : List [tpd.Tree ]) extends AnyVal {
0 commit comments