8000
We read every piece of feedback, and take your input very seriously.
2 parents d0a11e0 + 24d8ecb commit 6887748Copy full SHA for 6887748
compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
@@ -1773,8 +1773,6 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
1773
val returnUnit = lambdaTarget.info.resultType.typeSymbol == defn.UnitClass
1774
val functionalInterfaceDesc: String = generatedType.descriptor
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
1779
val samMethod = atPhase(erasurePhase) {
1780
val samMethods = toDenot(functionalInterface).info.possibleSamMethods.toList
@@ -1787,7 +1785,21 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
1787
1785
}
1788
1786
1789
val methodName = samMethod.javaSimpleName
1790
- val samMethodType = asmMethodType(samMethod).toASMType
+ val samMethodBType = asmMethodType(samMethod)
+ val samMethodType = samMethodBType.toASMType
+
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
+ val instantiatedMethodType = instantiatedMethodBType.toASMType
1802
1803
// scala/bug#10334: make sure that a lambda object for `T => U` has a method `apply(T)U`, not only the `(Object)Object`
1804
// version. Using the lambda a structural type `{def apply(t: T): U}` causes a reflective lookup for this method.
1805
val needsGenericBridge = samMethodType != instantiatedMethodType