Fix ArrayStoreException from InlineClassAwareCaller.call

#KT-56650 Fixed
This commit is contained in:
wrongwrong
2023-02-14 16:13:31 +09:00
committed by Alexander Udalov
parent 10e9ef349f
commit b039f2e574
7 changed files with 57 additions and 8 deletions
@@ -43019,6 +43019,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/primaryValOfInlineClass.kt");
}
@Test
@TestMetadata("simpleConstructorWithInlineClassParameter.kt")
public void testSimpleConstructorWithInlineClassParameter() throws Exception {
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/simpleConstructorWithInlineClassParameter.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/reflection/call/inlineClasses/nonNullObject")
@TestDataPath("$PROJECT_ROOT")
@@ -43019,6 +43019,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/primaryValOfInlineClass.kt");
}
@Test
@TestMetadata("simpleConstructorWithInlineClassParameter.kt")
public void testSimpleConstructorWithInlineClassParameter() throws Exception {
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/simpleConstructorWithInlineClassParameter.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/reflection/call/inlineClasses/nonNullObject")
@TestDataPath("$PROJECT_ROOT")
@@ -0,0 +1,15 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
@JvmInline
value class Value(val value: String)
class A(val result: Value)
fun box(): String {
val args: Array<Value> = arrayOf(Value("OK"))
val a = (::A).call(*args)
return a.result.value
}
@@ -40901,6 +40901,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/primaryValOfInlineClass.kt");
}
@Test
@TestMetadata("simpleConstructorWithInlineClassParameter.kt")
public void testSimpleConstructorWithInlineClassParameter() throws Exception {
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/simpleConstructorWithInlineClassParameter.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/reflection/call/inlineClasses/nonNullObject")
@TestDataPath("$PROJECT_ROOT")
@@ -43019,6 +43019,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/primaryValOfInlineClass.kt");
}
@Test
@TestMetadata("simpleConstructorWithInlineClassParameter.kt")
public void testSimpleConstructorWithInlineClassParameter() throws Exception {
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/simpleConstructorWithInlineClassParameter.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/reflection/call/inlineClasses/nonNullObject")
@TestDataPath("$PROJECT_ROOT")
@@ -32674,6 +32674,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/primaryValOfInlineClass.kt");
}
@TestMetadata("simpleConstructorWithInlineClassParameter.kt")
public void testSimpleConstructorWithInlineClassParameter() throws Exception {
runTest("compiler/testData/codegen/box/reflection/call/inlineClasses/simpleConstructorWithInlineClassParameter.kt");
}
@TestMetadata("compiler/testData/codegen/box/reflection/call/inlineClasses/nonNullObject")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -125,16 +125,21 @@ internal class InlineClassAwareCaller<out M : Member?>(
val (range, unbox, box) = data
@Suppress("UNCHECKED_CAST")
val unboxed = args.copyOf() as Array<Any?>
for (index in range) {
val method = unbox[index]
val unboxed = Array(args.size) { index ->
val arg = args[index]
// Note that arg may be null in case we're calling a $default method and it's an optional parameter of an inline class type
unboxed[index] = if (method != null) {
if (arg != null) {
method.invoke(arg)
if (index in range) {
// Note that arg may be null in case we're calling a $default method and it's an optional parameter of an inline class type
val method = unbox[index]
if (method != null) {
if (arg != null) {
method.invoke(arg)
} else {
defaultPrimitiveValue(method.returnType)
}
} else {
defaultPrimitiveValue(method.returnType)
arg
}
} else {
arg