@@ -1773,8 +1773,6 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
1773
1773
val returnUnit = lambdaTarget.info.resultType.typeSymbol == defn.UnitClass
1774
1774
val functionalInterfaceDesc : String = generatedType.descriptor
1775
1775
val desc = capturedParamsTypes.map(tpe => toTypeKind(tpe)).mkString((" (" ), " " , " )" ) + functionalInterfaceDesc
1776
- // TODO specialization
1777
- val instantiatedMethodType = new MethodBType (lambdaParamTypes.map(p => toTypeKind(p)), toTypeKind(lambdaTarget.info.resultType)).toASMType
1778
1776
1779
1777
val samMethod = atPhase(erasurePhase) {
1780
1778
val samMethods = toDenot(functionalInterface).info.possibleSamMethods.toList
@@ -1787,7 +1785,29 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
1787
1785
}
1788
1786
1789
1787
val methodName = samMethod.javaSimpleName
1790
- val samMethodType = asmMethodType(samMethod).toASMType
1788
+ val samMethodBType = asmMethodType(samMethod)
1789
+ val samMethodType = samMethodBType.toASMType
1790
+
1791
+ def boxInstantiated (instantiatedType : BType , samType : BType ): BType =
1792
+ if (! samType.isPrimitive && instantiatedType.isPrimitive)
1793
+ boxedClassOfPrimitive(instantiatedType.asPrimitiveBType)
1794
+ else instantiatedType
1795
+ // TODO specialization
1796
+ val instantiatedMethodBType = new MethodBType (
1797
+ lambdaParamTypes.map(p => toTypeKind(p)),
1798
+ boxInstantiated(toTypeKind(lambdaTarget.info.resultType), samMethodBType.returnType)
1799
+ )
1800
+
1801
+ // check that types are equal for parameters and return type as required by spec of altMetafactory
1802
+ def checkInstantiated (a : BType , b : BType ): Boolean =
1803
+ (! a.isPrimitive && ! b.isPrimitive) || (a.isPrimitive && b.isPrimitive && a == b)
1804
+ assert(
1805
+ samMethodBType.argumentTypes.zip(instantiatedMethodBType.argumentTypes).forall(checkInstantiated) && checkInstantiated(samMethodBType.returnType,
1806
+ instantiatedMethodBType.returnType), s " Primitive types must be equal: ${samMethodBType} vs. $instantiatedMethodBType"
1807
+ )
1808
+
1809
+ val instantiatedMethodType = instantiatedMethodBType.toASMType
1810
+
1791
1811
// scala/bug#10334: make sure that a lambda object for `T => U` has a method `apply(T)U`, not only the `(Object)Object`
1792
1812
// version. Using the lambda a structural type `{def apply(t: T): U}` causes a reflective lookup for this method.
1793
1813
val needsGenericBridge = samMethodType != instantiatedMethodType
0 commit comments