@@ -73,18 +73,24 @@ class ExpandSAMs extends MiniPhase {
7373 }
7474
7575 val applyRhs = applyDef.rhs
76- val applyFn = applyDef.symbol.asTerm
76+ val applyFn = applyDef.symbol
7777
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 )
8894
8995 def isDefinedAtRhs (paramRefss : List [List [Tree ]]) = {
9096 val tru = Literal (Constant (true ))
@@ -115,13 +121,11 @@ class ExpandSAMs extends MiniPhase {
115121 }
116122 }
117123
124+ val constr = ctx.newConstructor(cls, Synthetic , Nil , Nil ).entered
118125 val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
119126 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 ))
125129 }
126130
127131 private def checkRefinements (tpe : Type , pos : Position )(implicit ctx : Context ): Type = tpe.dealias match {
0 commit comments