JVM_IR: support type parameters in @JvmOverload functions

This commit is contained in:
Georgy Bronnikov
2019-09-23 20:24:36 +03:00
parent 7467c80970
commit e38ff8753e
5 changed files with 42 additions and 0 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_OVERLOADS_FQ_NAME
@@ -59,6 +60,9 @@ private class JvmOverloadsAnnotationLowering(val context: JvmBackendContext) : C
IrDelegatingConstructorCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.irBuiltIns.unitType, target.symbol, target.descriptor)
else
IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, target.returnType, target.symbol)
for (arg in wrapperIrFunction.typeParameters) {
call.putTypeArgument(arg.index, arg.defaultType)
}
call.dispatchReceiver = wrapperIrFunction.dispatchReceiverParameter?.let { dispatchReceiver ->
IrGetValueImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: box.kt
class C {
@kotlin.jvm.JvmOverloads public fun <X> foo(x: X, s: String = "OK"): String {
return s
}
}
fun box(): String {
return A().test()
}
// FILE: A.java
public class A {
public String test() {
return new C().foo(42);
}
}
@@ -15159,6 +15159,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
}
@TestMetadata("typeParameters.kt")
public void testTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/typeParameters.kt");
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/varargs.kt");
@@ -15159,6 +15159,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
}
@TestMetadata("typeParameters.kt")
public void testTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/typeParameters.kt");
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/varargs.kt");
@@ -14044,6 +14044,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
}
@TestMetadata("typeParameters.kt")
public void testTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/typeParameters.kt");
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/varargs.kt");