@@ -43,10 +43,9 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
43
43
44
44
final case class LambdaMetaFactoryCapable (lambdaTarget : Symbol , arity : Int , functionalInterface : Symbol , sam : Symbol , bridges : List [Symbol ], isSerializable : Boolean )
45
45
46
- /**
47
- * Get the symbol of the target lifted lambda body method from a function. I.e. if
48
- * the function is {args => anonfun(args)} then this method returns anonfun's symbol
49
- */
46
+ /** Get the symbol of the target lifted lambda body method from a function. I.e. if
47
+ * the function is {args => anonfun(args)} then this method returns anonfun's symbol
48
+ */
50
49
private def targetMethod (fun : Function ): Symbol = fun match {
51
50
case Function (_, Apply (target, _)) => target.symbol
52
51
case _ =>
@@ -177,9 +176,11 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
177
176
val resTpOk = (
178
177
samResultType =:= UnitTpe
179
178
|| functionResultType =:= samResultType
180
- || (isReferenceType(samResultType) && isReferenceType(functionResultType))) // yes, this is what the spec says -- no further correspondence required
181
- if (resTpOk && (samParamTypes corresponds functionParamTypes){ (samParamTp, funParamTp) =>
182
- funParamTp =:= samParamTp || (isReferenceType(funParamTp) && isReferenceType(samParamTp) && funParamTp <:< samParamTp) }) target
179
+ || (isReferenceType(samResultType) && isReferenceType(functionResultType))) // per spec, no further correspondence required
180
+ def paramTpsOk = samParamTypes.corresponds(functionParamTypes)((samParamTp, funParamTp) =>
181
+ funParamTp =:= samParamTp ||
182
+ (isReferenceType(funParamTp) && isReferenceType(samParamTp) && funParamTp <:< samParamTp))
183
+ if (resTpOk && paramTpsOk) target
183
184
else {
184
185
// We have to construct a new lambda target that bridges to the one created by uncurry.
185
186
// The bridge must satisfy the above invariants, while also minimizing adaptation on our end.
@@ -194,7 +195,7 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
194
195
// which means the function's parameter -- even if it expects a value class -- will need to be
195
196
// boxed on the generic call to the sam method.
196
197
197
- val bridgeParamTypes = map2(samParamTypes, functionParamTypes){ (samParamTp, funParamTp) =>
198
+ val bridgeParamTypes = map2(samParamTypes, functionParamTypes) { (samParamTp, funParamTp) =>
198
199
if (isReferenceType(samParamTp) && funParamTp <:< samParamTp) funParamTp
199
200
else postErasure.elimErasedValueType(samParamTp)
200
201
}
@@ -243,9 +244,12 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
243
244
244
245
gen.mkMethodCall(Select (gen.mkAttributedThis(oldClass), target), capturedArgRefs ::: functionArgRefs)
245
246
}
247
+ val forwarderResultType =
248
+ if (samResultType.isInstanceOf [ErasedValueType ] && functionResultType.isInstanceOf [ErasedValueType ]) bridgeResultType
249
+ else functionResultType
246
250
247
251
val bridge = postErasure.newTransformer(unit).transform(DefDef (methSym, List (bridgeParams.map(ValDef (_))),
248
- adaptToType(forwarderCall setType functionResultType , bridgeResultType))).asInstanceOf [DefDef ]
252
+ adaptToType(forwarderCall. setType(forwarderResultType) , bridgeResultType))).asInstanceOf [DefDef ]
249
253
250
254
boxingBridgeMethods += bridge
251
255
bridge.symbol
0 commit comments