@@ -73,24 +73,21 @@ class ExpandSAMs extends MiniPhase {
73
73
}
74
74
75
75
val applyRhs = applyDef.rhs
76
- val applyFn = applyDef.symbol.asTerm
76
+ val applyFn = applyDef.symbol
77
77
78
- val MethodTpe (paramNames, paramTypes, _) = applyFn.info
79
- val isDefinedAtFn = applyFn.copy(
80
- name = nme.isDefinedAt,
81
- flags = Synthetic | Method ,
82
- info = MethodType (paramNames, paramTypes, defn.BooleanType )).asTerm
83
-
84
- val applyOrElseFn = applyFn.copy(
85
- name = nme.applyOrElse,
86
- flags = Synthetic | Method ,
87
- info = tpt.tpe.memberInfo(defn.PartialFunction_applyOrElse )).asTerm
78
+ def overrideSym (sym : Symbol ) = sym.copy(
79
+ owner = applyFn.owner,
80
+ flags = Synthetic | Method | Final ,
81
+ info = tpt.tpe.memberInfo(sym),
82
+ coord = tree.pos).asTerm
83
+ val isDefinedAtFn = overrideSym(defn.PartialFunction_isDefinedAt )
84
+ val applyOrElseFn = overrideSym(defn.PartialFunction_applyOrElse )
88
85
89
86
def isDefinedAtRhs (paramRefss : List [List [Tree ]]) = {
90
87
val tru = Literal (Constant (true ))
91
88
applyRhs match {
92
89
case tree @ Match (_, cases) =>
93
- def translateCase (cdef : CaseDef )=
90
+ def translateCase (cdef : CaseDef ) =
94
91
cpy.CaseDef (cdef)(body = tru).changeOwner(applyFn, isDefinedAtFn)
95
92
val paramRef = paramRefss.head.head
96
93
val defaultValue = Literal (Constant (false ))
@@ -109,15 +106,19 @@ class ExpandSAMs extends MiniPhase {
109
106
val defaultValue = defaultRef.select(nme.apply).appliedTo(paramRef)
110
107
translateMatch(tree, paramRef, cases.map(translateCase), defaultValue)
111
108
case _ =>
112
- ref(applyFn).appliedTo(paramRef)
109
+ applyRhs
110
+ .changeOwner(applyFn, applyOrElseFn)
111
+ .subst(param.symbol :: Nil , paramRef.symbol :: Nil )
113
112
}
114
113
}
115
114
116
115
val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
117
116
val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)))
118
117
119
- val anonCls = AnonClass (tpt.tpe :: Nil , List (applyFn, isDefinedAtFn, applyOrElseFn), List (nme.apply, nme.isDefinedAt, nme.applyOrElse))
120
- cpy.Block (tree)(List (applyDef, isDefinedAtDef, applyOrElseDef), anonCls)
118
+ val tpArgs = tpt.tpe.baseType(defn.PartialFunctionClass ).argInfos
119
+ val parent = defn.AbstractPartialFunctionType .appliedTo(tpArgs)
120
+ val anonCls = AnonClass (parent :: Nil , List (isDefinedAtFn, applyOrElseFn), List (nme.isDefinedAt, nme.applyOrElse))
121
+ cpy.Block (tree)(List (isDefinedAtDef, applyOrElseDef), anonCls)
121
122
}
122
123
123
124
private def checkRefinements (tpe : Type , pos : Position )(implicit ctx : Context ): Type = tpe.dealias match {
0 commit comments