diff --git a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt index a2a6c437ceb..e9ab026bc52 100644 --- a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt +++ b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt @@ -8,6 +8,7 @@ const val MaxUL = ULong.MAX_VALUE const val MinUL = ULong.MIN_VALUE val M = MaxUI.toULong() +val N = Int.MAX_VALUE.toUInt() fun testSimpleUIntLoop() { var s = 0 @@ -79,6 +80,28 @@ fun testMaxULdownToMinUL() { } } +fun testWrappingULongLoop() { + val MA = M - 1UL + val MB = M + 1UL + val xs = ArrayList() + for (i in MB downTo MA) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(MB, M, MA)) throw AssertionError("$xs") +} + +fun testWrappingUIntLoop() { + val NA = N - 1u + val NB = N + 1u + val xs = ArrayList() + for (i in NB downTo NA) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(NB, N, NA)) throw AssertionError("$xs") +} + fun box(): String { testSimpleUIntLoop() testEmptyUIntLoop() @@ -88,6 +111,8 @@ fun box(): String { testEmptyULongLoop2() testMaxUIdownToMinUI() testMaxULdownToMinUL() + testWrappingULongLoop() + testWrappingUIntLoop() return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedProgression.kt b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedProgression.kt index 30be82b0b09..64b0305be1d 100644 --- a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedProgression.kt +++ b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedProgression.kt @@ -8,6 +8,7 @@ const val MaxUL = ULong.MAX_VALUE const val MinUL = ULong.MIN_VALUE val M = MaxUI.toULong() +val N = Int.MAX_VALUE.toUInt() val p1 = 6u downTo 1u fun testSimpleUIntLoop() { @@ -87,6 +88,30 @@ fun testMaxULdownToMinUL() { } } +val MA = M - 1UL +val MB = M + 1UL +val p9 = MB downTo MA +fun testWrappingULongLoop() { + val xs = ArrayList() + for (i in p9) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(MB, M, MA)) throw AssertionError("$xs") +} + +val NA = N - 1u +val NB = N + 1u +val p10 = NB downTo NA +fun testWrappingUIntLoop() { + val xs = ArrayList() + for (i in p10) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(NB, N, NA)) throw AssertionError("$xs") +} + fun box(): String { testSimpleUIntLoop() testEmptyUIntLoop() @@ -96,6 +121,8 @@ fun box(): String { testEmptyULongLoop2() testMaxUIdownToMinUI() testMaxULdownToMinUL() + testWrappingULongLoop() + testWrappingUIntLoop() return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRange.kt b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRange.kt index 3bd84941347..e2adb793840 100644 --- a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRange.kt +++ b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRange.kt @@ -8,6 +8,7 @@ const val MaxUL = ULong.MAX_VALUE const val MinUL = ULong.MIN_VALUE val M = MaxUI.toULong() +val N = Int.MAX_VALUE.toUInt() val range1 = 1u .. 6u fun testSimpleUIntLoop() { @@ -87,6 +88,30 @@ fun testMaxULtoMinUL() { } } +val MA = M - 1UL +val MB = M + 1UL +val range9 = MA..MB +fun testWrappingULongLoop() { + val xs = ArrayList() + for (i in range9) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(MA, M, MB)) throw AssertionError("$xs") +} + +val NA = N - 1u +val NB = N + 1u +val range10 = NA..NB +fun testWrappingUIntLoop() { + val xs = ArrayList() + for (i in range10) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(NA, N, NB)) throw AssertionError("$xs") +} + fun box(): String { testSimpleUIntLoop() testEmptyUIntLoop() @@ -96,6 +121,8 @@ fun box(): String { testEmptyULongLoop2() testMaxUItoMinUI() testMaxULtoMinUL() + testWrappingULongLoop() + testWrappingUIntLoop() return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt index 35d2c461a92..cd08590d3c1 100644 --- a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt +++ b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt @@ -8,6 +8,7 @@ const val MaxUL = ULong.MAX_VALUE const val MinUL = ULong.MIN_VALUE val M = MaxUI.toULong() +val N = Int.MAX_VALUE.toUInt() fun testSimpleUIntLoop() { var s = 0 @@ -79,6 +80,28 @@ fun testMaxULtoMinUL() { } } +fun testWrappingULongLoop() { + val MA = M - 1UL + val MB = M + 1UL + val xs = ArrayList() + for (i in MA .. MB) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(MA, M, MB)) throw AssertionError("$xs") +} + +fun testWrappingUIntLoop() { + val NA = N - 1u + val NB = N + 1u + val xs = ArrayList() + for (i in NA .. NB) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(NA, N, NB)) throw AssertionError("$xs") +} + fun box(): String { testSimpleUIntLoop() testEmptyUIntLoop() @@ -88,6 +111,8 @@ fun box(): String { testEmptyULongLoop2() testMaxUItoMinUI() testMaxULtoMinUL() + testWrappingULongLoop() + testWrappingUIntLoop() return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt index 3ce9310fd75..cda21884435 100644 --- a/compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt +++ b/compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt @@ -8,6 +8,7 @@ const val MaxUL = ULong.MAX_VALUE const val MinUL = ULong.MIN_VALUE val M = MaxUI.toULong() +val N = Int.MAX_VALUE.toUInt() fun testSimpleUIntLoop() { var s = 0 @@ -79,6 +80,28 @@ fun testMaxULtoMinUL() { } } +fun testWrappingUIntLoop() { + val NA = N - 1u + val NB = N + 1u + val xs = ArrayList() + for (i in NA until NB) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(NA, N)) throw AssertionError("$xs") +} + +fun testWrappingULongLoop() { + val MA = M - 1UL + val MB = M + 1UL + val xs = ArrayList() + for (i in MA until MB) { + xs.add(i) + if (xs.size > 3) break + } + if (xs != listOf(MA, M)) throw AssertionError("$xs") +} + fun box(): String { testSimpleUIntLoop() testEmptyUIntLoop() @@ -88,6 +111,8 @@ fun box(): String { testEmptyULongLoop2() testMaxUItoMinUI() testMaxULtoMinUL() + testWrappingUIntLoop() + testWrappingULongLoop() return "OK" } \ No newline at end of file