diff --git a/compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt b/compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt new file mode 100644 index 00000000000..6da1957ed05 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt @@ -0,0 +1,47 @@ +// TODO: muted automatically, investigate should it be ran for JS_IR or not +// IGNORE_BACKEND: JS_IR + +// TODO: muted automatically, investigate should it be ran for JS or not +// IGNORE_BACKEND: JS + +// TODO: muted automatically, investigate should it be ran for NATIVE or not +// IGNORE_BACKEND: NATIVE + +// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT! +// WITH_RUNTIME + + +import java.lang.Integer.MAX_VALUE as MaxI +import java.lang.Integer.MIN_VALUE as MinI +import java.lang.Byte.MAX_VALUE as MaxB +import java.lang.Byte.MIN_VALUE as MinB +import java.lang.Short.MAX_VALUE as MaxS +import java.lang.Short.MIN_VALUE as MinS +import java.lang.Long.MAX_VALUE as MaxL +import java.lang.Long.MIN_VALUE as MinL +import java.lang.Character.MAX_VALUE as MaxC +import java.lang.Character.MIN_VALUE as MinC + +fun box(): String { + val list1 = ArrayList() + val range1 = 0 downTo MaxI step 3 + for (i in range1) { + list1.add(i) + if (list1.size > 23) break + } + if (list1 != listOf()) { + return "Wrong elements for 0 downTo MaxI step 3: $list1" + } + + val list2 = ArrayList() + val range2 = 0 downTo MaxL step 3 + for (i in range2) { + list2.add(i) + if (list2.size > 23) break + } + if (list2 != listOf()) { + return "Wrong elements for 0 downTo MaxL step 3: $list2" + } + + return "OK" +} diff --git a/compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt b/compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt new file mode 100644 index 00000000000..099c6d6837b --- /dev/null +++ b/compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt @@ -0,0 +1,47 @@ +// TODO: muted automatically, investigate should it be ran for JS_IR or not +// IGNORE_BACKEND: JS_IR + +// TODO: muted automatically, investigate should it be ran for JS or not +// IGNORE_BACKEND: JS + +// TODO: muted automatically, investigate should it be ran for NATIVE or not +// IGNORE_BACKEND: NATIVE + +// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT! +// WITH_RUNTIME + + +import java.lang.Integer.MAX_VALUE as MaxI +import java.lang.Integer.MIN_VALUE as MinI +import java.lang.Byte.MAX_VALUE as MaxB +import java.lang.Byte.MIN_VALUE as MinB +import java.lang.Short.MAX_VALUE as MaxS +import java.lang.Short.MIN_VALUE as MinS +import java.lang.Long.MAX_VALUE as MaxL +import java.lang.Long.MIN_VALUE as MinL +import java.lang.Character.MAX_VALUE as MaxC +import java.lang.Character.MIN_VALUE as MinC + +fun box(): String { + val list1 = ArrayList() + val range1 = 0..MinI step 3 + for (i in range1) { + list1.add(i) + if (list1.size > 23) break + } + if (list1 != listOf()) { + return "Wrong elements for 0..MinI step 3: $list1" + } + + val list2 = ArrayList() + val range2 = 0L..MinL step 3 + for (i in range2) { + list2.add(i) + if (list2.size > 23) break + } + if (list2 != listOf()) { + return "Wrong elements for 0L..MinL step 3: $list2" + } + + return "OK" +} diff --git a/compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt b/compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt new file mode 100644 index 00000000000..5c758aadf29 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt @@ -0,0 +1,45 @@ +// TODO: muted automatically, investigate should it be ran for JS_IR or not +// IGNORE_BACKEND: JS_IR + +// TODO: muted automatically, investigate should it be ran for JS or not +// IGNORE_BACKEND: JS + +// TODO: muted automatically, investigate should it be ran for NATIVE or not +// IGNORE_BACKEND: NATIVE + +// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT! +// WITH_RUNTIME + + +import java.lang.Integer.MAX_VALUE as MaxI +import java.lang.Integer.MIN_VALUE as MinI +import java.lang.Byte.MAX_VALUE as MaxB +import java.lang.Byte.MIN_VALUE as MinB +import java.lang.Short.MAX_VALUE as MaxS +import java.lang.Short.MIN_VALUE as MinS +import java.lang.Long.MAX_VALUE as MaxL +import java.lang.Long.MIN_VALUE as MinL +import java.lang.Character.MAX_VALUE as MaxC +import java.lang.Character.MIN_VALUE as MinC + +fun box(): String { + val list1 = ArrayList() + for (i in 0 downTo MaxI step 3) { + list1.add(i) + if (list1.size > 23) break + } + if (list1 != listOf()) { + return "Wrong elements for 0 downTo MaxI step 3: $list1" + } + + val list2 = ArrayList() + for (i in 0 downTo MaxL step 3) { + list2.add(i) + if (list2.size > 23) break + } + if (list2 != listOf()) { + return "Wrong elements for 0 downTo MaxL step 3: $list2" + } + + return "OK" +} diff --git a/compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt b/compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt new file mode 100644 index 00000000000..b5e117f9e1e --- /dev/null +++ b/compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt @@ -0,0 +1,45 @@ +// TODO: muted automatically, investigate should it be ran for JS_IR or not +// IGNORE_BACKEND: JS_IR + +// TODO: muted automatically, investigate should it be ran for JS or not +// IGNORE_BACKEND: JS + +// TODO: muted automatically, investigate should it be ran for NATIVE or not +// IGNORE_BACKEND: NATIVE + +// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT! +// WITH_RUNTIME + + +import java.lang.Integer.MAX_VALUE as MaxI +import java.lang.Integer.MIN_VALUE as MinI +import java.lang.Byte.MAX_VALUE as MaxB +import java.lang.Byte.MIN_VALUE as MinB +import java.lang.Short.MAX_VALUE as MaxS +import java.lang.Short.MIN_VALUE as MinS +import java.lang.Long.MAX_VALUE as MaxL +import java.lang.Long.MIN_VALUE as MinL +import java.lang.Character.MAX_VALUE as MaxC +import java.lang.Character.MIN_VALUE as MinC + +fun box(): String { + val list1 = ArrayList() + for (i in 0..MinI step 3) { + list1.add(i) + if (list1.size > 23) break + } + if (list1 != listOf()) { + return "Wrong elements for 0..MinI step 3: $list1" + } + + val list2 = ArrayList() + for (i in 0L..MinL step 3) { + list2.add(i) + if (list2.size > 23) break + } + if (list2 != listOf()) { + return "Wrong elements for 0L..MinL step 3: $list2" + } + + return "OK" +} 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 367144e9bcd..5056ffd3562 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 @@ -15820,6 +15820,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/ranges/expression/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/expression/progressionDownToMinValue.kt"); @@ -16351,6 +16361,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/ranges/literal/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/literal/progressionDownToMinValue.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 851a8e6c6eb..948c59f4610 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -15820,6 +15820,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/ranges/expression/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/expression/progressionDownToMinValue.kt"); @@ -16351,6 +16361,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/ranges/literal/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/literal/progressionDownToMinValue.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1ca40cef10f..68ed208c787 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15820,6 +15820,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/ranges/expression/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/expression/progressionDownToMinValue.kt"); @@ -16351,6 +16361,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/ranges/literal/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/literal/progressionDownToMinValue.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java index 95a59153290..7f2bd14f642 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java @@ -106,6 +106,7 @@ public class GenerateRangesCodegenTestData { private static final List INTEGER_PRIMITIVES = Arrays.asList("Integer", "Byte", "Short", "Long", "Character"); + // TODO: Use common MIN_VALUE/MAX_VALUE constants and remove these exclusions private static final List IGNORED_FOR_JS_BACKEND = Arrays.asList( "inexactDownToMinValue.kt", "inexactToMaxValue.kt", @@ -116,7 +117,10 @@ public class GenerateRangesCodegenTestData { "progressionMaxValueMinusTwoToMaxValue.kt", "progressionMaxValueToMaxValue.kt", "progressionMaxValueToMinValue.kt", - "progressionMinValueToMinValue.kt"); + "progressionMinValueToMinValue.kt", + "overflowZeroToMinValue.kt", + "overflowZeroDownToMaxValue.kt" + ); private static final List IGNORED_FOR_NATIVE_BACKEND = Arrays.asList( "inexactDownToMinValue.kt", @@ -128,7 +132,9 @@ public class GenerateRangesCodegenTestData { "progressionMaxValueMinusTwoToMaxValue.kt", "progressionMaxValueToMaxValue.kt", "progressionMaxValueToMinValue.kt", - "progressionMinValueToMinValue.kt" + "progressionMinValueToMinValue.kt", + "overflowZeroToMinValue.kt", + "overflowZeroDownToMaxValue.kt" ); private static void writeIgnoreBackendDirective(PrintWriter out, String backendName) { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 3c438269e19..8407768fde5 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -14110,6 +14110,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/expression/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/expression/progressionDownToMinValue.kt"); @@ -14641,6 +14651,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/literal/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/literal/progressionDownToMinValue.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 ca829c7c9f3..ba89c86c66d 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 @@ -14110,6 +14110,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/expression/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/expression/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/expression/progressionDownToMinValue.kt"); @@ -14641,6 +14651,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/literal/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroDownToMaxValue.kt"); + } + + @TestMetadata("overflowZeroToMinValue.kt") + public void testOverflowZeroToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/literal/overflowZeroToMinValue.kt"); + } + @TestMetadata("progressionDownToMinValue.kt") public void testProgressionDownToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/literal/progressionDownToMinValue.kt"); diff --git a/libraries/stdlib/jvm/test/ranges/RangeIterationJVMTest.kt b/libraries/stdlib/jvm/test/ranges/RangeIterationJVMTest.kt index e2a32addc7e..08f4aa7ee94 100644 --- a/libraries/stdlib/jvm/test/ranges/RangeIterationJVMTest.kt +++ b/libraries/stdlib/jvm/test/ranges/RangeIterationJVMTest.kt @@ -93,6 +93,11 @@ public class RangeIterationJVMTest : RangeIterationTestBase() { doTest((MaxC - 5)..MaxC step 3, (MaxC - 5), (MaxC - 2), 3, listOf((MaxC - 5), (MaxC - 2))) } + @Test fun overflowZeroToMinValue() { + doTest(0..MinI step 3, 0, MinI, 3, listOf()) + doTest(0L..MinL step 3, 0, MinL, 3.toLong(), listOf()) + } + @Test fun progressionDownToMinValue() { doTest((MinI + 2) downTo MinI step 1, MinI + 2, MinI, -1, listOf(MinI + 2, MinI + 1, MinI)) doTest((MinB + 2).toByte() downTo MinB step 1, (MinB + 2).toInt(), MinB.toInt(), -1, listOf((MinB + 2).toInt(), (MinB + 1).toInt(), MinB.toInt())) @@ -110,4 +115,9 @@ public class RangeIterationJVMTest : RangeIterationTestBase() { doTest((MinC + 5) downTo MinC step 3, (MinC + 5), (MinC + 2), -3, listOf((MinC + 5), (MinC + 2))) } + + @Test fun overflowZeroDownToMaxValue() { + doTest(0 downTo MaxI step 3, 0, MaxI, -3, listOf()) + doTest(0 downTo MaxL step 3, 0, MaxL, -3.toLong(), listOf()) + } } \ No newline at end of file diff --git a/libraries/stdlib/test/ranges/ProgressionLastElementTest.kt b/libraries/stdlib/test/ranges/ProgressionLastElementTest.kt index 321f927e9b1..33462032dea 100644 --- a/libraries/stdlib/test/ranges/ProgressionLastElementTest.kt +++ b/libraries/stdlib/test/ranges/ProgressionLastElementTest.kt @@ -54,6 +54,7 @@ class ProgressionLastElementTest { doTest(MIN + 1, MAX, MAX, MAX) doTest(MAX - 7, MAX, 3, MAX - 1) doTest(MAX - 7, MAX, MAX, MAX - 7) + doTest(0, MAX, -3, MAX) // end == MIN doTest(0, MIN, MIN, MIN) @@ -61,6 +62,7 @@ class ProgressionLastElementTest { doTest(MAX, MIN, MIN, -1) doTest(MIN + 7, MIN, -3, MIN + 1) doTest(MIN + 7, MIN, MIN, MIN + 7) + doTest(0, MIN, 3, MIN) } @Test fun iterateToFinalElement() {