@@ -35,8 +35,8 @@ class ExpandSAMs extends MiniPhase {
3535 tpt.tpe match {
3636 case NoType => tree // it's a plain function
3737 case tpe @ SAMType (_) if tpe.isRef(defn.PartialFunctionClass ) =>
38- checkRefinements(tpe, fn.pos)
39- toPartialFunction(tree)
38+ val tpe1 = checkRefinements(tpe, fn.pos)
39+ toPartialFunction(tree, tpe1 )
4040 case tpe @ SAMType (_) if isPlatformSam(tpe.classSymbol.asClass) =>
4141 checkRefinements(tpe, fn.pos)
4242 tree
@@ -50,10 +50,9 @@ class ExpandSAMs extends MiniPhase {
5050 tree
5151 }
5252
53- private def toPartialFunction (tree : Block )(implicit ctx : Context ): Tree = {
53+ private def toPartialFunction (tree : Block , tpe : Type )(implicit ctx : Context ): Tree = {
5454 val Block (
55- (applyDef @ DefDef (nme.ANON_FUN , Nil , List (List (param)), _, _)) :: Nil ,
56- Closure (_, _, tpt)) = tree
55+ (applyDef @ DefDef (nme.ANON_FUN , Nil , List (List (param)), _, _)) :: Nil , _) = tree
5756
5857 def translateMatch (tree : Match , selector : Tree , cases : List [CaseDef ], defaultValue : Tree ) = {
5958 assert(tree.selector.symbol == param.symbol)
@@ -78,7 +77,7 @@ class ExpandSAMs extends MiniPhase {
7877 def overrideSym (sym : Symbol ) = sym.copy(
7978 owner = applyFn.owner,
8079 flags = Synthetic | Method | Final ,
81- info = tpt. tpe.memberInfo(sym),
80+ info = tpe.memberInfo(sym),
8281 coord = tree.pos).asTerm
8382 val isDefinedAtFn = overrideSym(defn.PartialFunction_isDefinedAt )
8483 val applyOrElseFn = overrideSym(defn.PartialFunction_applyOrElse )
@@ -115,8 +114,7 @@ class ExpandSAMs extends MiniPhase {
115114 val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
116115 val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)))
117116
118- val tpArgs = tpt.tpe.baseType(defn.PartialFunctionClass ).argInfos
119- val parent = defn.AbstractPartialFunctionType .appliedTo(tpArgs)
117+ val parent = defn.AbstractPartialFunctionType .appliedTo(tpe.argInfos)
120118 val anonCls = AnonClass (parent :: Nil , List (isDefinedAtFn, applyOrElseFn), List (nme.isDefinedAt, nme.applyOrElse))
121119 cpy.Block (tree)(List (isDefinedAtDef, applyOrElseDef), anonCls)
122120 }
@@ -126,7 +124,7 @@ class ExpandSAMs extends MiniPhase {
126124 if (name.isTermName && tpe.member(name).symbol.ownersIterator.isEmpty) // if member defined in the refinement
127125 ctx.error(" Lambda does not define " + name, pos)
128126 checkRefinements(parent, pos)
129- case _ =>
127+ case tpe =>
130128 tpe
131129 }
132130
0 commit comments