Revert fbf2424838:
postpone "transparent semantics for spread operator" until Java-related design issues are resolved (java.utils.Arrays#asList).
This commit is contained in:
@@ -2683,24 +2683,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasSpread) {
|
if (hasSpread) {
|
||||||
boolean arrayOfReferences = KotlinBuiltIns.isArray(outType);
|
|
||||||
if (size == 1) {
|
if (size == 1) {
|
||||||
// Arrays.copyOf(array, newLength)
|
gen(arguments.get(0).getArgumentExpression(), type);
|
||||||
ValueArgument argument = arguments.get(0);
|
|
||||||
Type arrayType = arrayOfReferences ? Type.getType("[Ljava/lang/Object;")
|
|
||||||
: Type.getType("[" + elementType.getDescriptor());
|
|
||||||
gen(argument.getArgumentExpression(), type);
|
|
||||||
v.dup();
|
|
||||||
v.arraylength();
|
|
||||||
v.invokestatic("java/util/Arrays", "copyOf", Type.getMethodDescriptor(arrayType, arrayType, Type.INT_TYPE), false);
|
|
||||||
if (arrayOfReferences) {
|
|
||||||
v.checkcast(type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String owner;
|
String owner;
|
||||||
String addDescriptor;
|
String addDescriptor;
|
||||||
String toArrayDescriptor;
|
String toArrayDescriptor;
|
||||||
|
boolean arrayOfReferences = KotlinBuiltIns.isArray(outType);
|
||||||
if (arrayOfReferences) {
|
if (arrayOfReferences) {
|
||||||
owner = "kotlin/jvm/internal/SpreadBuilder";
|
owner = "kotlin/jvm/internal/SpreadBuilder";
|
||||||
addDescriptor = "(Ljava/lang/Object;)V";
|
addDescriptor = "(Ljava/lang/Object;)V";
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
fun <T> copyArray(vararg data: T): Array<out T> = data
|
|
||||||
|
|
||||||
inline fun <reified T> reifiedCopyArray(vararg data: T): Array<out T> = data
|
|
||||||
|
|
||||||
fun copyIntArray(vararg data: Int): IntArray = data
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
val sarr = arrayOf("OK")
|
|
||||||
val sarr2 = copyArray(*sarr)
|
|
||||||
sarr[0] = "Array was not copied"
|
|
||||||
assertEquals(sarr2[0], "OK", "Failed: Array<String>")
|
|
||||||
|
|
||||||
var rsarr = arrayOf("OK")
|
|
||||||
var rsarr2 = reifiedCopyArray(*rsarr)
|
|
||||||
rsarr[0] = "Array was not copied"
|
|
||||||
assertEquals(rsarr2[0], "OK", "Failed: Array<String>, reified copy")
|
|
||||||
|
|
||||||
val iarr = IntArray(1)
|
|
||||||
iarr[0] = 1
|
|
||||||
val iarr2 = copyIntArray(*iarr)
|
|
||||||
iarr[0] = 42
|
|
||||||
assertEquals(iarr2[0], 1, "Failed: IntArray")
|
|
||||||
|
|
||||||
return "OK"
|
|
||||||
}
|
|
||||||
@@ -91,8 +91,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
Method main = generateFunction("test");
|
Method main = generateFunction("test");
|
||||||
String[] args = {"mama", "papa"};
|
String[] args = {"mama", "papa"};
|
||||||
String[] result = (String []) main.invoke(null, new Object[] {args});
|
String[] result = (String []) main.invoke(null, new Object[] {args});
|
||||||
assertTrue(args != result);
|
assertTrue(args == result);
|
||||||
assertTrue(Arrays.equals(args, result));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayAsVararg2() throws InvocationTargetException, IllegalAccessException {
|
public void testArrayAsVararg2() throws InvocationTargetException, IllegalAccessException {
|
||||||
|
|||||||
-6
@@ -4591,12 +4591,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/vararg"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/vararg"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("spreadCopiesArray.kt")
|
|
||||||
public void testSpreadCopiesArray() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/vararg/spreadCopiesArray.kt");
|
|
||||||
doTestWithStdlib(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("varargInFunParam.kt")
|
@TestMetadata("varargInFunParam.kt")
|
||||||
public void testVarargInFunParam() throws Exception {
|
public void testVarargInFunParam() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/vararg/varargInFunParam.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/vararg/varargInFunParam.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user