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");
}
@Test
@TestMetadata("kt46092.kt")
public void testKt46092() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt46092.kt");
}
@Test
@TestMetadata("kt581.kt")
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) {
addFunction("copyOf", arrayType, isStatic = true).apply {
addValueParameter("original", arrayType)
addValueParameter("newLength", irBuiltIns.intType)
arraysCopyOfFunctions[arrayType] = this
arraysCopyOfFunctions[arrayType.classifierOrFail] = this
}
}
@@ -771,15 +771,12 @@ class JvmSymbols(
}
fun getArraysCopyOfFunction(arrayType: IrSimpleType): IrSimpleFunctionSymbol {
val copyOf = arraysCopyOfFunctions[arrayType]
return when {
copyOf != null ->
copyOf.symbol
arrayType.classifierOrFail == array ->
arraysCopyOfFunctions[arrayOfAnyNType]!!.symbol
else ->
throw AssertionError("Array type expected: ${arrayType.render()}")
}
val classifier = arrayType.classifier
val copyOf = arraysCopyOfFunctions[classifier]
if (copyOf != null)
return copyOf.symbol
else
throw AssertionError("Array type expected: ${arrayType.render()}")
}
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");
}
@Test
@TestMetadata("kt46092.kt")
public void testKt46092() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt46092.kt");
}
@Test
@TestMetadata("kt581.kt")
public void testKt581() throws Exception {
@@ -41056,6 +41056,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
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
@TestMetadata("kt581.kt")
public void testKt581() throws Exception {
@@ -33008,6 +33008,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
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")
public void testKt581() throws Exception {
runTest("compiler/testData/codegen/box/vararg/kt581.kt");