Skip to content

Commit 82e7d20

Browse files
committed
Improve ArrayApplyOptTest
- Avoid using the generic Array constructor when possible - In the situation where we do need to use the generic Array constructor, add an expected type to make the example more realistic and reveal whether a checkcast is needed in bytecode to make use of the Array at all. With these changes, using Array or IArray produce the exact same bytecode.
1 parent 672daa8 commit 82e7d20

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

compiler/test/dotty/tools/backend/jvm/ArrayApplyOptTest.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ class ArrayApplyOptTest extends DottyBytecodeTest {
5656

5757
@Test def testArrayApplyByte = {
5858
val init = List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(BASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_2), Op(BASTORE))
59-
test("Array[Byte](1, 2)", newArray2Opcodes(T_BYTE, init))
60-
test("IArray[Byte](1, 2)", newArray2Opcodes(T_BYTE, init :+ TypeOp(CHECKCAST, "[B")))
59+
test("Array(1: Byte, 2: Byte)", newArray2Opcodes(T_BYTE, init))
60+
test("IArray(1: Byte, 2: Byte)", newArray2Opcodes(T_BYTE, init))
6161
}
6262

6363
@Test def testArrayApplyShort = {
6464
val init = List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(SASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_2), Op(SASTORE))
65-
test("Array[Short](1, 2)", newArray2Opcodes(T_SHORT, init))
66-
test("IArray[Short](1, 2)", newArray2Opcodes(T_SHORT, init :+ TypeOp(CHECKCAST, "[S")))
65+
test("Array(1: Short, 2: Short)", newArray2Opcodes(T_SHORT, init))
66+
test("IArray(1: Short, 2: Short)", newArray2Opcodes(T_SHORT, init))
6767
}
6868

6969
@Test def testArrayApplyInt = {
7070
val init = List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(IASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_2), Op(IASTORE))
7171
test("Array(1, 2)", newArray2Opcodes(T_INT, init))
7272
test("IArray(1, 2)", newArray2Opcodes(T_INT, init))
7373

74-
val init2 = List(Op(DUP), Op(ICONST_0), Field(GETSTATIC, "Foo$", "MODULE$", "LFoo$;"), Invoke(INVOKEVIRTUAL, "Foo$", "t", "()I", false), Op(IASTORE), Op(DUP), Op(ICONST_1), Field(GETSTATIC, "Foo$", "MODULE$", "LFoo$;"), Invoke(INVOKEVIRTUAL, "Foo$", "t", "()I", false), Op(IASTORE))
75-
test("""Array[T](t, t)""", newArray2Opcodes(T_INT, init2))
76-
test("""IArray[T](t, t)""", newArray2Opcodes(T_INT, init2 :+ TypeOp(CHECKCAST, "[I")))
74+
val init2 = List(Op(DUP), Op(ICONST_0), Field(GETSTATIC, "Foo$", "MODULE$", "LFoo$;"), Invoke(INVOKEVIRTUAL, "Foo$", "t", "()I", false), Op(IASTORE), Op(DUP), Op(ICONST_1), Field(GETSTATIC, "Foo$", "MODULE$", "LFoo$;"), Invoke(INVOKEVIRTUAL, "Foo$", "t", "()I", false), Op(IASTORE), TypeOp(CHECKCAST, "[I"))
75+
test("""Array[T](t, t): Array[T]""", newArray2Opcodes(T_INT, init2))
76+
test("""IArray[T](t, t): IArray[T]""", newArray2Opcodes(T_INT, init2))
7777
}
7878

7979
@Test def testArrayApplyLong = {

0 commit comments

Comments
 (0)