diff --git a/compiler/testData/codegen/box/ranges/contains/inArrayIndices.kt b/compiler/testData/codegen/box/ranges/contains/inArrayIndices.kt new file mode 100644 index 00000000000..df6931c18b3 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/contains/inArrayIndices.kt @@ -0,0 +1,21 @@ +// WITH_RUNTIME + +val ints = intArrayOf(1, 2, 3) +val objs = arrayOf(1, 2, 3) + +val i1 = 1 + +fun box(): String { + // NB partially const-folded in JVM BE + if (!(1 in ints.indices)) return "Fail 1 in IntArray.indices" + if (1 !in ints.indices) return "Fail 1 !in IntArray.indices" + if (!(1 in objs.indices)) return "Fail 1 in Array.indices" + if (1 !in objs.indices) return "Fail 1 !in Array.indices" + + if (!(i1 in ints.indices)) return "Fail i1 in IntArray.indices" + if (i1 !in ints.indices) return "Fail i1 !in IntArray.indices" + if (!(i1 in objs.indices)) return "Fail i1 in Array.indices" + if (i1 !in objs.indices) return "Fail i1 !in Array.indices" + + return "OK" +} diff --git a/compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt b/compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt new file mode 100644 index 00000000000..64657d9d6b9 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME + +fun testPrimitiveArray(i: Int, ints: IntArray) = i in ints.indices + +fun testObjectArray(i: Int, xs: Array) = i in xs.indices + +// 0 INVOKESTATIC kotlin/collections/ArraysKt.getIndices +// 0 INVOKEVIRTUAL kotlin/ranges/IntRange.contains +// 2 ARRAYLENGTH diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 23bd62a4861..6fe8e7f11d1 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -13183,6 +13183,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("inArrayIndices.kt") + public void testInArrayIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inArrayIndices.kt"); + doTest(fileName); + } + @TestMetadata("inCharSequence.kt") public void testInCharSequence() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inCharSequence.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 660b51d8675..4c4e5462737 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13183,6 +13183,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("inArrayIndices.kt") + public void testInArrayIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inArrayIndices.kt"); + doTest(fileName); + } + @TestMetadata("inCharSequence.kt") public void testInCharSequence() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inCharSequence.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 4a0d04a7e47..66e9cc23621 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1859,6 +1859,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("inArrayIndices.kt") + public void testInArrayIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt"); + doTest(fileName); + } + @TestMetadata("inComparableRangeLiteral.kt") public void testInComparableRangeLiteral() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/ranges/inComparableRangeLiteral.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6dc7600d6f1..6494097b72c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13183,6 +13183,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("inArrayIndices.kt") + public void testInArrayIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inArrayIndices.kt"); + doTest(fileName); + } + @TestMetadata("inCharSequence.kt") public void testInCharSequence() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inCharSequence.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index b806f283119..768fe40aab9 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -14791,6 +14791,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("inArrayIndices.kt") + public void testInArrayIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inArrayIndices.kt"); + doTest(fileName); + } + @TestMetadata("inCharSequence.kt") public void testInCharSequence() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inCharSequence.kt");