@@ -73,18 +73,24 @@ 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
+ val tpArgs = tpt.tpe.baseType(defn.PartialFunctionClass ).argInfos
79
+ val parent = defn.AbstractPartialFunctionType .appliedTo(tpArgs)
80
+ val cls = ctx.newNormalizedClassSymbol(
81
+ applyDef.symbol.owner,
82
+ tpnme.ANON_CLASS ,
83
+ Synthetic | Final ,
84
+ parent :: Nil ,
85
+ coord = tree.pos)
86
+
87
+ def overrideSym (sym : Symbol ) = sym.copy(
88
+ owner = cls,
89
+ flags = sym.flags &~ Deferred | Override | Final | Synthetic ,
90
+ info = cls.typeRef.memberInfo(sym),
91
+ coord = tree.pos).entered.asTerm
92
+ val isDefinedAtFn = overrideSym(defn.AbstractPartialFunction_isDefinedAt )
93
+ val applyOrElseFn = overrideSym(defn.AbstractPartialFunction_applyOrElse )
88
94
89
95
def isDefinedAtRhs (paramRefss : List [List [Tree ]]) = {
90
96
val tru = Literal (Constant (true ))
@@ -115,13 +121,11 @@ class ExpandSAMs extends MiniPhase {
115
121
}
116
122
}
117
123
124
+ val constr = ctx.newConstructor(cls, Synthetic , Nil , Nil ).entered
118
125
val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
119
126
val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)))
120
-
121
- val tpArgs = tpt.tpe.baseType(defn.PartialFunctionClass ).argInfos
122
- val parent = defn.AbstractPartialFunctionType .appliedTo(tpArgs)
123
- val anonCls = AnonClass (parent :: Nil , List (isDefinedAtFn, applyOrElseFn), List (nme.isDefinedAt, nme.applyOrElse))
124
- cpy.Block (tree)(List (isDefinedAtDef, applyOrElseDef), anonCls)
127
+ val cdef = ClassDef (cls, DefDef (constr), List (isDefinedAtDef, applyOrElseDef))
128
+ cpy.Block (tree)(cdef :: Nil , New (cls.typeRef, Nil ))
125
129
}
126
130
127
131
private def checkRefinements (tpe : Type , pos : Position )(implicit ctx : Context ): Type = tpe.dealias match {
0 commit comments