JVM_IR: do not set ACC_VARARGS if vararg is not the last parameter
Fun fact: this is not actually validated when loading the class; and even when compiling a java file against a class file that does this, only javac 9 has a check (1.8 and before simply crashes with NullPointerException somewhere deep inside the compiler).
This commit is contained in:
+1
-1
@@ -108,7 +108,7 @@ open class FunctionCodegen(
|
||||
|
||||
val visibility = irFunction.getVisibilityAccessFlag()
|
||||
val staticFlag = if (isStatic) Opcodes.ACC_STATIC else 0
|
||||
val varargFlag = if (irFunction.valueParameters.any { it.varargElementType != null }) Opcodes.ACC_VARARGS else 0
|
||||
val varargFlag = if (irFunction.valueParameters.lastOrNull()?.varargElementType != null) Opcodes.ACC_VARARGS else 0
|
||||
val deprecation = irFunction.deprecationFlags
|
||||
val bridgeFlag = if (
|
||||
irFunction.origin == IrDeclarationOrigin.BRIDGE ||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: A.kt
|
||||
class A {
|
||||
fun f(vararg xs: String, y: String) = xs[0] + y
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
public class B {
|
||||
public static String f() {
|
||||
return new A().f(new String[]{"O"}, "K");
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: C.kt
|
||||
fun box() = B.f()
|
||||
+5
@@ -27773,6 +27773,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/vararg/kt796_797.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notInLastPosition.kt")
|
||||
public void testNotInLastPosition() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/notInLastPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleAssignmentToVarargsInFunction.kt")
|
||||
public void testSingleAssignmentToVarargsInFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/singleAssignmentToVarargsInFunction.kt");
|
||||
|
||||
+5
@@ -26590,6 +26590,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/vararg/kt796_797.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notInLastPosition.kt")
|
||||
public void testNotInLastPosition() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/notInLastPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleAssignmentToVarargsInFunction.kt")
|
||||
public void testSingleAssignmentToVarargsInFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/singleAssignmentToVarargsInFunction.kt");
|
||||
|
||||
+5
@@ -26323,6 +26323,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/vararg/kt796_797.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notInLastPosition.kt")
|
||||
public void testNotInLastPosition() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/notInLastPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleAssignmentToVarargsInFunction.kt")
|
||||
public void testSingleAssignmentToVarargsInFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/singleAssignmentToVarargsInFunction.kt");
|
||||
|
||||
+5
@@ -26323,6 +26323,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/vararg/kt796_797.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notInLastPosition.kt")
|
||||
public void testNotInLastPosition() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/notInLastPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleAssignmentToVarargsInFunction.kt")
|
||||
public void testSingleAssignmentToVarargsInFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/vararg/singleAssignmentToVarargsInFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user