@@ -71,15 +71,18 @@ class ExpandSAMs extends MiniPhase {
71
71
case PartialFunctionRHS (pf) =>
72
72
val anonSym = anon.symbol
73
73
74
+ val parents = List (defn.AbstractPartialFunctionType .appliedTo(tpe.argInfos), defn.SerializableType )
75
+ val pfSym = ctx.newNormalizedClassSymbol(anonSym.owner, tpnme.ANON_CLASS , Synthetic | Final , parents, coord = tree.pos)
76
+
74
77
def overrideSym (sym : Symbol ) = sym.copy(
75
- owner = anonSym.owner ,
76
- flags = Synthetic | Method | Final ,
78
+ owner = pfSym ,
79
+ flags = Synthetic | Method | Final | Override ,
77
80
info = tpe.memberInfo(sym),
78
- coord = tree.pos).asTerm
81
+ coord = tree.pos).asTerm.entered
79
82
val isDefinedAtFn = overrideSym(defn.PartialFunction_isDefinedAt )
80
83
val applyOrElseFn = overrideSym(defn.PartialFunction_applyOrElse )
81
84
82
- def translateMatch (tree : Match , pfParam : Symbol , cases : List [CaseDef ], defaultValue : Tree ) = {
85
+ def translateMatch (tree : Match , pfParam : Symbol , cases : List [CaseDef ], defaultValue : Tree )( implicit ctx : Context ) = {
83
86
val selector = tree.selector
84
87
val selectorTpe = selector.tpe.widen
85
88
val defaultSym = ctx.newSymbol(pfParam.owner, nme.WILDCARD , Synthetic , selectorTpe)
@@ -96,7 +99,7 @@ class ExpandSAMs extends MiniPhase {
96
99
// And we need to update all references to 'param'
97
100
}
98
101
99
- def isDefinedAtRhs (paramRefss : List [List [Tree ]]) = {
102
+ def isDefinedAtRhs (paramRefss : List [List [Tree ]])( implicit ctx : Context ) = {
100
103
val tru = Literal (Constant (true ))
101
104
def translateCase (cdef : CaseDef ) =
102
105
cpy.CaseDef (cdef)(body = tru).changeOwner(anonSym, isDefinedAtFn)
@@ -105,20 +108,19 @@ class ExpandSAMs extends MiniPhase {
105
108
translateMatch(pf, paramRef.symbol, pf.cases.map(translateCase), defaultValue)
106
109
}
107
110
108
- def applyOrElseRhs (paramRefss : List [List [Tree ]]) = {
111
+ def applyOrElseRhs (paramRefss : List [List [Tree ]])( implicit ctx : Context ) = {
109
112
val List (paramRef, defaultRef) = paramRefss.head
110
113
def translateCase (cdef : CaseDef ) =
111
114
cdef.changeOwner(anonSym, applyOrElseFn)
112
115
val defaultValue = defaultRef.select(nme.apply).appliedTo(paramRef)
113
116
translateMatch(pf, paramRef.symbol, pf.cases.map(translateCase), defaultValue)
114
117
}
115
118
116
- val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
117
- val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)))
118
-
119
- val parents = List (defn.AbstractPartialFunctionType .appliedTo(tpe.argInfos), defn.SerializableType )
120
- val anonCls = AnonClass (parents, List (isDefinedAtFn, applyOrElseFn), List (nme.isDefinedAt, nme.applyOrElse))
121
- cpy.Block (tree)(List (isDefinedAtDef, applyOrElseDef), anonCls)
119
+ val constr = ctx.newConstructor(pfSym, Synthetic , Nil , Nil ).entered
120
+ val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)(ctx.withOwner(isDefinedAtFn))))
121
+ val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)(ctx.withOwner(applyOrElseFn))))
122
+ val pfDef = ClassDef (pfSym, DefDef (constr), List (isDefinedAtDef, applyOrElseDef))
123
+ cpy.Block (tree)(pfDef :: Nil , New (pfSym.typeRef, Nil ))
122
124
123
125
case _ =>
124
126
val found = tpe.baseType(defn.FunctionClass (1 ))
0 commit comments