@@ -90,7 +90,7 @@ class ExpandSAMs extends MiniPhase {
90
90
val tru = Literal (Constant (true ))
91
91
applyRhs match {
92
92
case tree @ Match (_, cases) =>
93
- def translateCase (cdef : CaseDef )=
93
+ def translateCase (cdef : CaseDef ) =
94
94
cpy.CaseDef (cdef)(body = tru).changeOwner(applyFn, isDefinedAtFn)
95
95
val paramRef = paramRefss.head.head
96
96
val defaultValue = Literal (Constant (false ))
@@ -109,15 +109,19 @@ class ExpandSAMs extends MiniPhase {
109
109
val defaultValue = defaultRef.select(nme.apply).appliedTo(paramRef)
110
110
translateMatch(tree, paramRef, cases.map(translateCase), defaultValue)
111
111
case _ =>
112
- ref(applyFn).appliedTo(paramRef)
112
+ applyRhs
113
+ .changeOwner(applyFn, applyOrElseFn)
114
+ .subst(param.symbol :: Nil , paramRef.symbol :: Nil )
113
115
}
114
116
}
115
117
116
118
val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
117
119
val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)))
118
120
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)
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)
121
125
}
122
126
123
127
private def checkRefinements (tpe : Type , pos : Position )(implicit ctx : Context ): Type = tpe.dealias match {
0 commit comments