Remove redundant ACC_VARARGS on methods generated with @JvmOverloads
#KT-15424 Fixed
This commit is contained in:
+6
-5
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmOverloadsAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.OtherOrigin
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind
|
||||
import org.jetbrains.org.objectweb.asm.Label
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -129,11 +128,13 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
|
||||
) {
|
||||
val typeMapper = state.typeMapper
|
||||
val isStatic = AsmUtil.isStaticMethod(contextKind, functionDescriptor)
|
||||
val flags = AsmUtil.getCommonCallableFlags(functionDescriptor) or
|
||||
(if (isStatic) Opcodes.ACC_STATIC else 0) or
|
||||
(if (functionDescriptor.modality == Modality.FINAL && functionDescriptor !is ConstructorDescriptor) Opcodes.ACC_FINAL else 0)
|
||||
|
||||
val baseMethodFlags = AsmUtil.getCommonCallableFlags(functionDescriptor) and Opcodes.ACC_VARARGS.inv()
|
||||
val remainingParameters = getRemainingParameters(functionDescriptor.original, substituteCount)
|
||||
val flags =
|
||||
baseMethodFlags or
|
||||
(if (isStatic) Opcodes.ACC_STATIC else 0) or
|
||||
(if (functionDescriptor.modality == Modality.FINAL && functionDescriptor !is ConstructorDescriptor) Opcodes.ACC_FINAL else 0) or
|
||||
(if (remainingParameters.lastOrNull()?.varargElementType != null) Opcodes.ACC_VARARGS else 0)
|
||||
val signature = typeMapper.mapSignature(functionDescriptor, contextKind, remainingParameters, false)
|
||||
val mv = classBuilder.newMethod(OtherOrigin(methodElement, functionDescriptor), flags,
|
||||
signature.asmMethod.name,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
// FILE: test.kt
|
||||
|
||||
@JvmOverloads
|
||||
fun foo(id: Int, vararg pairs: String = emptyArray()): String {
|
||||
return "$id: ${java.util.Arrays.toString(pairs)}"
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun foo2(id: Int, s: Int = 56, vararg pairs: String): String {
|
||||
return "$id, $s: ${java.util.Arrays.toString(pairs)}"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A.bar1() != "1: []") return "fail 1"
|
||||
if (A.bar2() != "2: [OK]") return "fail 2"
|
||||
if (A.bar3() != "3, 56: []") return "fail 3"
|
||||
if (A.bar4() != "4, 56: [OK]") return "fail 4"
|
||||
if (A.bar5() != "5, 1491: [OK]") return "fail 5"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
public class A {
|
||||
public static String bar1() {
|
||||
return TestKt.foo(1);
|
||||
}
|
||||
|
||||
public static String bar2() {
|
||||
return TestKt.foo(2, "OK");
|
||||
}
|
||||
|
||||
public static String bar3() {
|
||||
return TestKt.foo2(3);
|
||||
}
|
||||
|
||||
public static String bar4() {
|
||||
return TestKt.foo2(4, "OK");
|
||||
}
|
||||
|
||||
public static String bar5() {
|
||||
return TestKt.foo2(5, 1491, "OK");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@kotlin.Metadata
|
||||
public final class TestKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public synthetic static method foo$default(p0: int, p1: java.lang.String[], p2: int, p3: java.lang.Object): java.lang.String
|
||||
public final static @kotlin.jvm.JvmOverloads @org.jetbrains.annotations.NotNull @synthetic.kotlin.jvm.GeneratedByJvmOverloads method foo(p0: int): java.lang.String
|
||||
public final static @kotlin.jvm.JvmOverloads @org.jetbrains.annotations.NotNull method foo(p0: int, @org.jetbrains.annotations.NotNull p1: java.lang.String[]): java.lang.String
|
||||
public synthetic static method foo2$default(p0: int, p1: int, p2: java.lang.String[], p3: int, p4: java.lang.Object): java.lang.String
|
||||
public final static @kotlin.jvm.JvmOverloads @org.jetbrains.annotations.NotNull @synthetic.kotlin.jvm.GeneratedByJvmOverloads method foo2(p0: int, @org.jetbrains.annotations.NotNull p1: java.lang.String[]): java.lang.String
|
||||
public final static @kotlin.jvm.JvmOverloads @org.jetbrains.annotations.NotNull method foo2(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String[]): java.lang.String
|
||||
}
|
||||
+6
@@ -9563,6 +9563,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noRedundantVarargs.kt")
|
||||
public void testNoRedundantVarargs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/noRedundantVarargs.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonDefaultParameter.kt")
|
||||
public void testNonDefaultParameter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/nonDefaultParameter.kt");
|
||||
|
||||
@@ -9563,6 +9563,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noRedundantVarargs.kt")
|
||||
public void testNoRedundantVarargs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/noRedundantVarargs.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonDefaultParameter.kt")
|
||||
public void testNonDefaultParameter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmOverloads/nonDefaultParameter.kt");
|
||||
|
||||
Reference in New Issue
Block a user