Generate correct varargs flag for @JvmOverloads-generated methods

#KT-14186 Fixed
This commit is contained in:
Dmitry Jemerov
2016-11-17 11:21:49 +01:00
parent 16a133bf5c
commit d3ccbe8172
6 changed files with 42 additions and 2 deletions
@@ -228,7 +228,7 @@ public class AsmUtil {
return flags;
}
private static int getCommonCallableFlags(FunctionDescriptor functionDescriptor) {
public static int getCommonCallableFlags(FunctionDescriptor functionDescriptor) {
int flags = getVisibilityAccessFlag(functionDescriptor);
flags |= getVarargsFlag(functionDescriptor);
flags |= getDeprecatedAccessFlag(functionDescriptor);
@@ -123,7 +123,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
) {
val typeMapper = state.typeMapper
val isStatic = AsmUtil.isStaticMethod(contextKind, functionDescriptor)
val flags = AsmUtil.getVisibilityAccessFlag(functionDescriptor) or (if (isStatic) Opcodes.ACC_STATIC else 0)
val flags = AsmUtil.getCommonCallableFlags(functionDescriptor) or (if (isStatic) Opcodes.ACC_STATIC else 0)
val remainingParameters = getRemainingParameters(functionDescriptor.original, substituteCount)
val signature = typeMapper.mapSignature(functionDescriptor, contextKind, remainingParameters, false)
val mv = classBuilder.newMethod(OtherOrigin(methodElement, functionDescriptor), flags,
+16
View File
@@ -0,0 +1,16 @@
// IGNORE_BACKEND: JS
// WITH_RUNTIME
class C {
@JvmOverloads
fun foo(bar: Int = 0, vararg status: String) {
}
}
fun box(): String {
val c = C()
val m = c.javaClass.getMethod("foo", Array<String>::class.java)
return if (m.isVarArgs) "OK" else "fail"
}
@@ -8638,6 +8638,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
doTest(fileName);
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/varargs.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/jvmStatic")
@@ -8638,6 +8638,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
doTest(fileName);
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/varargs.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/jvmStatic")
@@ -10468,6 +10468,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
}
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/varargs.kt");
try {
doTest(fileName);
}
catch (Throwable ignore) {
return;
}
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
}
}
@TestMetadata("compiler/testData/codegen/box/jvmStatic")