JVM_IR KT-46092 fix array spread operator in Kotlin->Java call

This commit is contained in:
Dmitry Petrov
2021-04-15 13:08:39 +03:00
committed by TeamCityServer
parent b5fae96934
commit cc415f62b5
6 changed files with 52 additions and 11 deletions
@@ -41056,6 +41056,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/vararg/kt45187.kt"); runTest("compiler/testData/codegen/box/vararg/kt45187.kt");
} }
@Test
@TestMetadata("kt46092.kt")
public void testKt46092() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt46092.kt");
}
@Test @Test
@TestMetadata("kt581.kt") @TestMetadata("kt581.kt")
public void testKt581() throws Exception { public void testKt581() throws Exception {
@@ -745,13 +745,13 @@ class JvmSymbols(
} }
} }
private val arraysCopyOfFunctions = HashMap<IrSimpleType, IrSimpleFunction>() private val arraysCopyOfFunctions = HashMap<IrClassifierSymbol, IrSimpleFunction>()
private fun IrClass.addArraysCopyOfFunction(arrayType: IrSimpleType) { private fun IrClass.addArraysCopyOfFunction(arrayType: IrSimpleType) {
addFunction("copyOf", arrayType, isStatic = true).apply { addFunction("copyOf", arrayType, isStatic = true).apply {
addValueParameter("original", arrayType) addValueParameter("original", arrayType)
addValueParameter("newLength", irBuiltIns.intType) addValueParameter("newLength", irBuiltIns.intType)
arraysCopyOfFunctions[arrayType] = this arraysCopyOfFunctions[arrayType.classifierOrFail] = this
} }
} }
@@ -771,15 +771,12 @@ class JvmSymbols(
} }
fun getArraysCopyOfFunction(arrayType: IrSimpleType): IrSimpleFunctionSymbol { fun getArraysCopyOfFunction(arrayType: IrSimpleType): IrSimpleFunctionSymbol {
val copyOf = arraysCopyOfFunctions[arrayType] val classifier = arrayType.classifier
return when { val copyOf = arraysCopyOfFunctions[classifier]
copyOf != null -> if (copyOf != null)
copyOf.symbol return copyOf.symbol
arrayType.classifierOrFail == array -> else
arraysCopyOfFunctions[arrayOfAnyNType]!!.symbol throw AssertionError("Array type expected: ${arrayType.render()}")
else ->
throw AssertionError("Array type expected: ${arrayType.render()}")
}
} }
private val javaLangInteger: IrClassSymbol = createClass(FqName("java.lang.Integer")) { klass -> private val javaLangInteger: IrClassSymbol = createClass(FqName("java.lang.Integer")) { klass ->
+21
View File
@@ -0,0 +1,21 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: kt46092.kt
class CharSequenceBackedByChars : CharArrayCharSequence {
constructor(chars: CharArray) : super(*chars)
fun test(): String = string
}
fun box() = CharSequenceBackedByChars(charArrayOf('O', 'K')).test()
// FILE: CharArrayCharSequence.java
public class CharArrayCharSequence {
protected final String string;
public CharArrayCharSequence(char... chars) {
string = new String(chars);
}
}
@@ -41032,6 +41032,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/vararg/kt45187.kt"); runTest("compiler/testData/codegen/box/vararg/kt45187.kt");
} }
@Test
@TestMetadata("kt46092.kt")
public void testKt46092() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt46092.kt");
}
@Test @Test
@TestMetadata("kt581.kt") @TestMetadata("kt581.kt")
public void testKt581() throws Exception { public void testKt581() throws Exception {
@@ -41056,6 +41056,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/vararg/kt45187.kt"); runTest("compiler/testData/codegen/box/vararg/kt45187.kt");
} }
@Test
@TestMetadata("kt46092.kt")
public void testKt46092() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt46092.kt");
}
@Test @Test
@TestMetadata("kt581.kt") @TestMetadata("kt581.kt")
public void testKt581() throws Exception { public void testKt581() throws Exception {
@@ -33008,6 +33008,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/vararg/kt45187.kt"); runTest("compiler/testData/codegen/box/vararg/kt45187.kt");
} }
@TestMetadata("kt46092.kt")
public void testKt46092() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt46092.kt");
}
@TestMetadata("kt581.kt") @TestMetadata("kt581.kt")
public void testKt581() throws Exception { public void testKt581() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt581.kt"); runTest("compiler/testData/codegen/box/vararg/kt581.kt");