Support passing inline class values with spread operator

This commit is contained in:
Mikhail Zarechenskiy
2018-02-12 06:21:39 +03:00
parent 3919dc94e1
commit e017e9cb5f
8 changed files with 71 additions and 2 deletions
@@ -2808,12 +2808,14 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
for (int i = 0; i != size; ++i) {
v.dup();
ValueArgument argument = arguments.get(i);
KtExpression argumentExpression = argument.getArgumentExpression();
KotlinType argumentKotlinType = kotlinType(argumentExpression);
if (argument.getSpreadElement() != null) {
gen(argument.getArgumentExpression(), OBJECT_TYPE);
gen(argumentExpression, OBJECT_TYPE, argumentKotlinType);
v.invokevirtual(owner, "addSpread", "(Ljava/lang/Object;)V", false);
}
else {
gen(argument.getArgumentExpression(), elementType);
gen(argumentExpression, elementType, argumentKotlinType);
v.invokevirtual(owner, "add", addDescriptor, false);
}
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +InlineClasses
inline class UInt(val value: Int)
fun <T> last(vararg e: T): T = e[e.size - 1]
fun <T> first(vararg e: T): T = e[0]
fun box(): String {
val u0 = UInt(0)
val us = arrayOf(UInt(1), UInt(2), UInt(3))
if (last(u0, *us).value != 3) return "fail"
if (first(*us, u0).value != 1) return "fail"
if (first(u0, *us).value != 0) return "fail"
return "OK"
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +InlineClasses
inline class UInt(val u: Int)
fun <T> takeVarargs(vararg e: T) {}
fun test(u1: UInt, u2: UInt, us: Array<UInt>) {
takeVarargs(*us) // copy + checkcast
takeVarargs(u1, u2, *us) // 2 box + ...
}
// 2 INVOKESTATIC UInt\$Erased.box
// 0 INVOKEVIRTUAL UInt.unbox
// 2 CHECKCAST \[LUInt
// 0 CHECKCAST \[Ljava/lang/Integer
// 0 intValue
// 0 valueOf
@@ -10497,6 +10497,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("passInlineClassWithSpreadOperatorToVarargs.kt")
public void testPassInlineClassWithSpreadOperatorToVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/passInlineClassWithSpreadOperatorToVarargs.kt");
doTest(fileName);
}
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");
@@ -10497,6 +10497,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("passInlineClassWithSpreadOperatorToVarargs.kt")
public void testPassInlineClassWithSpreadOperatorToVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/passInlineClassWithSpreadOperatorToVarargs.kt");
doTest(fileName);
}
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");
@@ -2016,6 +2016,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
@TestMetadata("passInlineClassesWithSpreadOperatorToVarargs.kt")
public void testPassInlineClassesWithSpreadOperatorToVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineClasses/passInlineClassesWithSpreadOperatorToVarargs.kt");
doTest(fileName);
}
@TestMetadata("skipCallToUnderlyingValueOfInlineClass.kt")
public void testSkipCallToUnderlyingValueOfInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineClasses/skipCallToUnderlyingValueOfInlineClass.kt");
@@ -10497,6 +10497,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
doTest(fileName);
}
@TestMetadata("passInlineClassWithSpreadOperatorToVarargs.kt")
public void testPassInlineClassWithSpreadOperatorToVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/passInlineClassWithSpreadOperatorToVarargs.kt");
doTest(fileName);
}
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");
@@ -11481,6 +11481,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
doTest(fileName);
}
@TestMetadata("passInlineClassWithSpreadOperatorToVarargs.kt")
public void testPassInlineClassWithSpreadOperatorToVarargs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/passInlineClassWithSpreadOperatorToVarargs.kt");
doTest(fileName);
}
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");