@@ -35,8 +35,8 @@ class ExpandSAMs extends MiniPhase {
35
35
tpt.tpe match {
36
36
case NoType => tree // it's a plain function
37
37
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 )
40
40
case tpe @ SAMType (_) if isPlatformSam(tpe.classSymbol.asClass) =>
41
41
checkRefinements(tpe, fn.pos)
42
42
tree
@@ -50,10 +50,9 @@ class ExpandSAMs extends MiniPhase {
50
50
tree
51
51
}
52
52
53
- private def toPartialFunction (tree : Block )(implicit ctx : Context ): Tree = {
53
+ private def toPartialFunction (tree : Block , tpe : Type )(implicit ctx : Context ): Tree = {
54
54
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
57
56
58
57
def translateMatch (tree : Match , selector : Tree , cases : List [CaseDef ], defaultValue : Tree ) = {
59
58
assert(tree.selector.symbol == param.symbol)
@@ -78,7 +77,7 @@ class ExpandSAMs extends MiniPhase {
78
77
def overrideSym (sym : Symbol ) = sym.copy(
79
78
owner = applyFn.owner,
80
79
flags = Synthetic | Method | Final ,
81
- info = tpt. tpe.memberInfo(sym),
80
+ info = tpe.memberInfo(sym),
82
81
coord = tree.pos).asTerm
83
82
val isDefinedAtFn = overrideSym(defn.PartialFunction_isDefinedAt )
84
83
val applyOrElseFn = overrideSym(defn.PartialFunction_applyOrElse )
@@ -115,8 +114,7 @@ class ExpandSAMs extends MiniPhase {
115
114
val isDefinedAtDef = transformFollowingDeep(DefDef (isDefinedAtFn, isDefinedAtRhs(_)))
116
115
val applyOrElseDef = transformFollowingDeep(DefDef (applyOrElseFn, applyOrElseRhs(_)))
117
116
118
- val tpArgs = tpt.tpe.baseType(defn.PartialFunctionClass ).argInfos
119
- val parent = defn.AbstractPartialFunctionType .appliedTo(tpArgs)
117
+ val parent = defn.AbstractPartialFunctionType .appliedTo(tpe.argInfos)
120
118
val anonCls = AnonClass (parent :: Nil , List (isDefinedAtFn, applyOrElseFn), List (nme.isDefinedAt, nme.applyOrElse))
121
119
cpy.Block (tree)(List (isDefinedAtDef, applyOrElseDef), anonCls)
122
120
}
@@ -126,7 +124,7 @@ class ExpandSAMs extends MiniPhase {
126
124
if (name.isTermName && tpe.member(name).symbol.ownersIterator.isEmpty) // if member defined in the refinement
127
125
ctx.error(" Lambda does not define " + name, pos)
128
126
checkRefinements(parent, pos)
129
- case _ =>
127
+ case tpe =>
130
128
tpe
131
129
}
132
130
0 commit comments