@@ -90,7 +90,7 @@ class ExpandSAMs extends MiniPhase {
9090 val tru = Literal (Constant (true ))
9191 applyRhs match {
9292 case tree @ Match (_, cases) =>
93- def translateCase (cdef : CaseDef )=
93+ def translateCase (cdef : CaseDef ) =
9494 cpy.CaseDef (cdef)(body = tru).changeOwner(applyFn, isDefinedAtFn)
9595 val paramRef = paramRefss.head.head
9696 val defaultValue = Literal (Constant (false ))
@@ -109,15 +109,19 @@ class ExpandSAMs extends MiniPhase {
109109 val defaultValue = defaultRef.select(nme.apply).appliedTo(paramRef)
110110 translateMatch(tree, paramRef, cases.map(translateCase), defaultValue)
111111 case _ =>
112- ref(applyFn).appliedTo(paramRef)
112+ applyRhs
113+ .changeOwner(applyFn, applyOrElseFn)
114+ .subst(param.symbol :: Nil , paramRef.symbol :: Nil )
113115 }
114116 }
115117
116118 val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
117119 val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)))
118120
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)
121125 }
122126
123127 private def checkRefinements (tpe : Type , pos : Position )(implicit ctx : Context ): Type = tpe.dealias match {
0 commit comments