Generate correct varargs flag for @JvmOverloads-generated methods
#KT-14186 Fixed
This commit is contained in:
@@ -228,7 +228,7 @@ public class AsmUtil {
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getCommonCallableFlags(FunctionDescriptor functionDescriptor) {
|
public static int getCommonCallableFlags(FunctionDescriptor functionDescriptor) {
|
||||||
int flags = getVisibilityAccessFlag(functionDescriptor);
|
int flags = getVisibilityAccessFlag(functionDescriptor);
|
||||||
flags |= getVarargsFlag(functionDescriptor);
|
flags |= getVarargsFlag(functionDescriptor);
|
||||||
flags |= getDeprecatedAccessFlag(functionDescriptor);
|
flags |= getDeprecatedAccessFlag(functionDescriptor);
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
|
|||||||
) {
|
) {
|
||||||
val typeMapper = state.typeMapper
|
val typeMapper = state.typeMapper
|
||||||
val isStatic = AsmUtil.isStaticMethod(contextKind, functionDescriptor)
|
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 remainingParameters = getRemainingParameters(functionDescriptor.original, substituteCount)
|
||||||
val signature = typeMapper.mapSignature(functionDescriptor, contextKind, remainingParameters, false)
|
val signature = typeMapper.mapSignature(functionDescriptor, contextKind, remainingParameters, false)
|
||||||
val mv = classBuilder.newMethod(OtherOrigin(methodElement, functionDescriptor), flags,
|
val mv = classBuilder.newMethod(OtherOrigin(methodElement, functionDescriptor), flags,
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
+6
@@ -8638,6 +8638,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
|
||||||
doTest(fileName);
|
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")
|
@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");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt");
|
||||||
doTest(fileName);
|
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")
|
@TestMetadata("compiler/testData/codegen/box/jvmStatic")
|
||||||
|
|||||||
+12
@@ -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.");
|
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")
|
@TestMetadata("compiler/testData/codegen/box/jvmStatic")
|
||||||
|
|||||||
Reference in New Issue
Block a user