diff --git a/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/serializers/ParcelSerializer.kt b/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/serializers/ParcelSerializer.kt index f1b1a38d91e..f6ced53241b 100644 --- a/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/serializers/ParcelSerializer.kt +++ b/plugins/parcelize/parcelize-compiler/src/org/jetbrains/kotlin/parcelize/serializers/ParcelSerializer.kt @@ -100,11 +100,12 @@ interface ParcelSerializer { findCustomParcelerType(type)?.let { return TypeParcelerParcelSerializer(asmType, it, context.typeMapper) } return when { + // Somewhat inconsistently, there are no `Parcel.writeShortArray/createShortArray` methods, + // so we need to exclude "[S" here. asmType.descriptor == "[I" || asmType.descriptor == "[Z" || asmType.descriptor == "[B" || asmType.descriptor == "[C" - || asmType.descriptor == "[S" || asmType.descriptor == "[D" || asmType.descriptor == "[F" || asmType.descriptor == "[J" diff --git a/plugins/parcelize/parcelize-compiler/testData/box/shortArray.kt b/plugins/parcelize/parcelize-compiler/testData/box/shortArray.kt new file mode 100644 index 00000000000..5a64892e4e2 --- /dev/null +++ b/plugins/parcelize/parcelize-compiler/testData/box/shortArray.kt @@ -0,0 +1,24 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JVM + +@file:JvmName("TestKt") +package test + +import kotlinx.parcelize.* +import android.os.Parcel +import android.os.Parcelable + +@Parcelize +class A(val value: ShortArray) : Parcelable + +fun box() = parcelTest { parcel -> + val a = A(shortArrayOf(0, 1, 2, 3)) + a.writeToParcel(parcel, 0) + + val bytes = parcel.marshall() + parcel.unmarshall(bytes, 0, bytes.size) + parcel.setDataPosition(0) + + val a2 = parcelableCreator().createFromParcel(parcel) + assert(a.value.contentEquals(a2.value)) +} diff --git a/plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.ir.txt b/plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.ir.txt new file mode 100644 index 00000000000..05df7e3539b --- /dev/null +++ b/plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.ir.txt @@ -0,0 +1,378 @@ +public final class Test$Creator : java/lang/Object, android/os/Parcelable$Creator { + public void () + + public final Test createFromParcel(android.os.Parcel parcel) { + LABEL (L0) + ALOAD (1) + LDC (parcel) + INVOKESTATIC (kotlin/jvm/internal/Intrinsics, checkNotNullParameter, (Ljava/lang/Object;Ljava/lang/String;)V) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createByteArray, ()[B) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createCharArray, ()[C) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, readInt, ()I) + ISTORE (2) + ILOAD (2) + NEWARRAY (9) + ASTORE (3) + ICONST_0 + ISTORE (4) + ASTORE (6) + ASTORE (5) + LABEL (L1) + ILOAD (4) + ILOAD (2) + IF_ICMPEQ (L2) + ALOAD (3) + ILOAD (4) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, readInt, ()I) + I2S + SASTORE + ILOAD (4) + ICONST_1 + IADD + ISTORE (4) + GOTO (L1) + LABEL (L2) + ALOAD (5) + ALOAD (6) + ALOAD (3) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createIntArray, ()[I) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createLongArray, ()[J) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createByteArray, ()[B) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createCharArray, ()[C) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, readInt, ()I) + IFNE (L3) + ACONST_NULL + GOTO (L4) + LABEL (L3) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, readInt, ()I) + ISTORE (2) + ILOAD (2) + NEWARRAY (9) + ASTORE (3) + ICONST_0 + ISTORE (4) + ASTORE (11) + ASTORE (10) + ASTORE (9) + ASTORE (8) + ASTORE (7) + ASTORE (6) + ASTORE (5) + LABEL (L5) + ILOAD (4) + ILOAD (2) + IF_ICMPEQ (L6) + ALOAD (3) + ILOAD (4) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, readInt, ()I) + I2S + SASTORE + ILOAD (4) + ICONST_1 + IADD + ISTORE (4) + GOTO (L5) + LABEL (L6) + ALOAD (5) + ALOAD (6) + ALOAD (7) + ALOAD (8) + ALOAD (9) + ALOAD (10) + ALOAD (11) + ALOAD (3) + LABEL (L4) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createIntArray, ()[I) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createLongArray, ()[J) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createFloatArray, ()[F) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createDoubleArray, ()[D) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createFloatArray, ()[F) + ALOAD (1) + INVOKEVIRTUAL (android/os/Parcel, createDoubleArray, ()[D) + ASTORE (12) + ASTORE (13) + ASTORE (14) + ASTORE (15) + ASTORE (16) + ASTORE (17) + ASTORE (18) + ASTORE (19) + ASTORE (20) + ASTORE (21) + ASTORE (22) + ASTORE (23) + ASTORE (24) + ASTORE (25) + NEW + DUP + ALOAD (25) + ALOAD (24) + ALOAD (23) + ALOAD (22) + ALOAD (21) + ALOAD (20) + ALOAD (19) + ALOAD (18) + ALOAD (17) + ALOAD (16) + ALOAD (15) + ALOAD (14) + ALOAD (13) + ALOAD (12) + INVOKESPECIAL (Test, , ([B[C[S[I[J[B[C[S[I[J[F[D[F[D)V) + ARETURN + LABEL (L7) + } + + public java.lang.Object createFromParcel(android.os.Parcel source) { + LABEL (L0) + ALOAD (0) + ALOAD (1) + INVOKEVIRTUAL (Test$Creator, createFromParcel, (Landroid/os/Parcel;)LTest;) + ARETURN + LABEL (L1) + } + + public final Test[] newArray(int size) + + public java.lang.Object[] newArray(int size) +} + +public final class Test : java/lang/Object, android/os/Parcelable { + public final static android.os.Parcelable$Creator CREATOR + + private final byte[] a + + private final char[] b + + private final short[] c + + private final int[] d + + private final long[] e + + private final byte[] f + + private final char[] g + + private final short[] h + + private final int[] i + + private final long[] j + + private final float[] k + + private final double[] l + + private final float[] m + + private final double[] n + + static void () + + public void (byte[] a, char[] b, short[] c, int[] d, long[] e, byte[] f, char[] g, short[] h, int[] i, long[] j, float[] k, double[] l, float[] m, double[] n) + + public final byte[] component1() + + public final long[] component10() + + public final float[] component11() + + public final double[] component12() + + public final float[] component13() + + public final double[] component14() + + public final char[] component2() + + public final short[] component3() + + public final int[] component4() + + public final long[] component5() + + public final byte[] component6() + + public final char[] component7() + + public final short[] component8() + + public final int[] component9() + + public final Test copy(byte[] a, char[] b, short[] c, int[] d, long[] e, byte[] f, char[] g, short[] h, int[] i, long[] j, float[] k, double[] l, float[] m, double[] n) + + public static Test copy$default(Test p0, byte[] p1, char[] p2, short[] p3, int[] p4, long[] p5, byte[] p6, char[] p7, short[] p8, int[] p9, long[] p10, float[] p11, double[] p12, float[] p13, double[] p14, int p15, java.lang.Object p16) + + public int describeContents() + + public boolean equals(java.lang.Object other) + + public final byte[] getA() + + public final char[] getB() + + public final short[] getC() + + public final int[] getD() + + public final long[] getE() + + public final byte[] getF() + + public final char[] getG() + + public final short[] getH() + + public final int[] getI() + + public final long[] getJ() + + public final float[] getK() + + public final double[] getL() + + public final float[] getM() + + public final double[] getN() + + public int hashCode() + + public java.lang.String toString() + + public void writeToParcel(android.os.Parcel out, int flags) { + LABEL (L0) + ALOAD (1) + LDC (out) + INVOKESTATIC (kotlin/jvm/internal/Intrinsics, checkNotNullParameter, (Ljava/lang/Object;Ljava/lang/String;)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, a, [B) + INVOKEVIRTUAL (android/os/Parcel, writeByteArray, ([B)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, b, [C) + INVOKEVIRTUAL (android/os/Parcel, writeCharArray, ([C)V) + ALOAD (0) + GETFIELD (Test, c, [S) + ASTORE (3) + ALOAD (3) + ARRAYLENGTH + ISTORE (4) + ALOAD (1) + ILOAD (4) + INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V) + ICONST_0 + ISTORE (5) + LABEL (L1) + ILOAD (5) + ILOAD (4) + IF_ICMPEQ (L2) + ALOAD (1) + ALOAD (3) + ILOAD (5) + SALOAD + INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V) + ILOAD (5) + ICONST_1 + IADD + ISTORE (5) + GOTO (L1) + LABEL (L2) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, d, [I) + INVOKEVIRTUAL (android/os/Parcel, writeIntArray, ([I)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, e, [J) + INVOKEVIRTUAL (android/os/Parcel, writeLongArray, ([J)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, f, [B) + INVOKEVIRTUAL (android/os/Parcel, writeByteArray, ([B)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, g, [C) + INVOKEVIRTUAL (android/os/Parcel, writeCharArray, ([C)V) + ALOAD (0) + GETFIELD (Test, h, [S) + ASTORE (3) + ALOAD (3) + IFNONNULL (L3) + ALOAD (1) + ICONST_0 + INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V) + GOTO (L4) + LABEL (L3) + ALOAD (1) + ICONST_1 + INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V) + ALOAD (3) + ARRAYLENGTH + ISTORE (4) + ALOAD (1) + ILOAD (4) + INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V) + ICONST_0 + ISTORE (5) + LABEL (L5) + ILOAD (5) + ILOAD (4) + IF_ICMPEQ (L4) + ALOAD (1) + ALOAD (3) + ILOAD (5) + SALOAD + INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V) + ILOAD (5) + ICONST_1 + IADD + ISTORE (5) + GOTO (L5) + LABEL (L4) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, i, [I) + INVOKEVIRTUAL (android/os/Parcel, writeIntArray, ([I)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, j, [J) + INVOKEVIRTUAL (android/os/Parcel, writeLongArray, ([J)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, k, [F) + INVOKEVIRTUAL (android/os/Parcel, writeFloatArray, ([F)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, l, [D) + INVOKEVIRTUAL (android/os/Parcel, writeDoubleArray, ([D)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, m, [F) + INVOKEVIRTUAL (android/os/Parcel, writeFloatArray, ([F)V) + ALOAD (1) + ALOAD (0) + GETFIELD (Test, n, [D) + INVOKEVIRTUAL (android/os/Parcel, writeDoubleArray, ([D)V) + RETURN + LABEL (L6) + } +} diff --git a/plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.kt b/plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.kt new file mode 100644 index 00000000000..68b769f9d9e --- /dev/null +++ b/plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.kt @@ -0,0 +1,26 @@ +// CURIOUS_ABOUT writeToParcel, createFromParcel +// WITH_RUNTIME + +// The JVM backend doesn't support ShortArray +// IGNORE_BACKEND: JVM + +import kotlinx.parcelize.* +import android.os.Parcelable + +@Parcelize +data class Test( + val a: ByteArray, + val b: CharArray, + val c: ShortArray, + val d: IntArray, + val e: LongArray, + val f: ByteArray?, + val g: CharArray?, + val h: ShortArray?, + val i: IntArray?, + val j: LongArray?, + val k: FloatArray, + val l: DoubleArray, + val m: FloatArray?, + val n: DoubleArray? +) : Parcelable diff --git a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBoxTestGenerated.java b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBoxTestGenerated.java index 705e11ecf26..922ed0f2d61 100644 --- a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBoxTestGenerated.java +++ b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBoxTestGenerated.java @@ -350,6 +350,11 @@ public class ParcelizeBoxTestGenerated extends AbstractParcelizeBoxTest { runTest("plugins/parcelize/parcelize-compiler/testData/box/sealedClass.kt"); } + @TestMetadata("shortArray.kt") + public void testShortArray() throws Exception { + runTest("plugins/parcelize/parcelize-compiler/testData/box/shortArray.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("plugins/parcelize/parcelize-compiler/testData/box/simple.kt"); diff --git a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBytecodeListingTestGenerated.java b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBytecodeListingTestGenerated.java index 0d4b9b0eb8d..96230d48ccc 100644 --- a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBytecodeListingTestGenerated.java +++ b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeBytecodeListingTestGenerated.java @@ -110,6 +110,11 @@ public class ParcelizeBytecodeListingTestGenerated extends AbstractParcelizeByte runTest("plugins/parcelize/parcelize-compiler/testData/codegen/parcelableCreator.kt"); } + @TestMetadata("primitiveArrays.kt") + public void testPrimitiveArrays() throws Exception { + runTest("plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.kt"); + } + @TestMetadata("serializable.kt") public void testSerializable() throws Exception { runTest("plugins/parcelize/parcelize-compiler/testData/codegen/serializable.kt"); diff --git a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBoxTestGenerated.java b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBoxTestGenerated.java index 679592dcef0..9eb17b74a43 100644 --- a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBoxTestGenerated.java +++ b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBoxTestGenerated.java @@ -350,6 +350,11 @@ public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest { runTest("plugins/parcelize/parcelize-compiler/testData/box/sealedClass.kt"); } + @TestMetadata("shortArray.kt") + public void testShortArray() throws Exception { + runTest("plugins/parcelize/parcelize-compiler/testData/box/shortArray.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("plugins/parcelize/parcelize-compiler/testData/box/simple.kt"); diff --git a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBytecodeListingTestGenerated.java b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBytecodeListingTestGenerated.java index d3ee9672a8d..ef50f4dd2ad 100644 --- a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBytecodeListingTestGenerated.java +++ b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/ParcelizeIrBytecodeListingTestGenerated.java @@ -110,6 +110,11 @@ public class ParcelizeIrBytecodeListingTestGenerated extends AbstractParcelizeIr runTest("plugins/parcelize/parcelize-compiler/testData/codegen/parcelableCreator.kt"); } + @TestMetadata("primitiveArrays.kt") + public void testPrimitiveArrays() throws Exception { + runTest("plugins/parcelize/parcelize-compiler/testData/codegen/primitiveArrays.kt"); + } + @TestMetadata("serializable.kt") public void testSerializable() throws Exception { runTest("plugins/parcelize/parcelize-compiler/testData/codegen/serializable.kt");