diff --git a/compiler/testData/codegen/box/binaryOp/overflowChar.kt b/compiler/testData/codegen/box/binaryOp/overflowChar.kt index 0f06f4969fd..9fc3a9adc82 100644 --- a/compiler/testData/codegen/box/binaryOp/overflowChar.kt +++ b/compiler/testData/codegen/box/binaryOp/overflowChar.kt @@ -1,10 +1,11 @@ fun box(): String { - val c1: Char = 0.toChar() + val c1: Char = Char.MIN_VALUE val c2 = c1 - 1 - if (c2 < c1) return "fail: 0.toChar() - 1 should overflow to positive." + if (c2 < c1) return "fail: Char.MIN_VALUE - 1 should overflow to positive." - val c3 = c2 + 1 - if (c3 > c2) return "fail: FFFF.toChar() + 1 should overflow to zero." + val c3: Char = Char.MAX_VALUE + val c4 = c3 + 1 + if (c4 > c3) return "fail: Char.MAX_VALUE + 1 should overflow to zero." return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValue.kt b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValue.kt index 4af3c19ea1b..2a70ba6b146 100644 --- a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValue.kt +++ b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValue.kt @@ -1,6 +1,6 @@ // WITH_RUNTIME -const val M = 0.toChar() +const val M = Char.MIN_VALUE fun box(): String { var count = 0 diff --git a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValueReversed.kt b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValueReversed.kt index fc86ffe8ed2..86dd4d322b4 100644 --- a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValueReversed.kt +++ b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInDownToCharMinValueReversed.kt @@ -1,7 +1,7 @@ // IGNORE_BACKEND: JS_IR // WITH_RUNTIME -const val M = 0.toChar() +const val M = Char.MIN_VALUE fun box(): String { var count = 0 diff --git a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValue.kt b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValue.kt index e21db89dbc7..d883d096a61 100644 --- a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValue.kt +++ b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValue.kt @@ -1,5 +1,5 @@ // IGNORE_BACKEND: JS_IR -const val M = 0xFFFF.toChar() +const val M = Char.MAX_VALUE fun box(): String { var count = 0 diff --git a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValueReversed.kt b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValueReversed.kt index 701069bb1bd..22fc80cf935 100644 --- a/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValueReversed.kt +++ b/compiler/testData/codegen/box/ranges/forWithPossibleOverflow/forInRangeToCharMaxValueReversed.kt @@ -1,7 +1,7 @@ // IGNORE_BACKEND: JS_IR // WITH_RUNTIME -const val M = 0xFFFF.toChar() +const val M = Char.MAX_VALUE fun box(): String { var count = 0 diff --git a/libraries/stdlib/jvm/test/numbers/BuiltinCompanionJVMTest.kt b/libraries/stdlib/jvm/test/numbers/BuiltinCompanionJVMTest.kt index 0db0fb690d1..e6b16607c99 100644 --- a/libraries/stdlib/jvm/test/numbers/BuiltinCompanionJVMTest.kt +++ b/libraries/stdlib/jvm/test/numbers/BuiltinCompanionJVMTest.kt @@ -55,6 +55,8 @@ class BuiltinCompanionJVMTest { @Test fun charTest() { val ch = Char + assertEquals(java.lang.Character.MIN_VALUE, ch.MIN_VALUE) + assertEquals(java.lang.Character.MAX_VALUE, ch.MAX_VALUE) assertEquals(java.lang.Character.MIN_SURROGATE, ch.MIN_SURROGATE) assertEquals(java.lang.Character.MAX_SURROGATE, ch.MAX_SURROGATE) assertEquals(java.lang.Character.MIN_LOW_SURROGATE, ch.MIN_LOW_SURROGATE) diff --git a/libraries/stdlib/test/numbers/NumbersTest.kt b/libraries/stdlib/test/numbers/NumbersTest.kt index 02e4663d648..78d558ec0d2 100644 --- a/libraries/stdlib/test/numbers/NumbersTest.kt +++ b/libraries/stdlib/test/numbers/NumbersTest.kt @@ -94,6 +94,15 @@ class NumbersTest { expect(Float.NEGATIVE_INFINITY) { -Float.MAX_VALUE * 2 } expect(0.0F) { Float.MIN_VALUE / 2.0F } } + + @Test fun charMinMaxValues() { + assertTrue(Char.MIN_VALUE.toInt() == 0) + assertTrue(Char.MAX_VALUE.toInt() > 0) + + // overflow behavior + expect(Char.MIN_VALUE) { Char.MAX_VALUE + one } + expect(Char.MAX_VALUE) { Char.MIN_VALUE - one } + } @Test fun doubleProperties() { for (value in listOf(1.0, 0.0, Double.MIN_VALUE, Double.MAX_VALUE)) diff --git a/libraries/stdlib/test/ranges/RangeTest.kt b/libraries/stdlib/test/ranges/RangeTest.kt index e2631ce2ee8..f2c72cf372d 100644 --- a/libraries/stdlib/test/ranges/RangeTest.kt +++ b/libraries/stdlib/test/ranges/RangeTest.kt @@ -172,7 +172,7 @@ public class RangeTest { assertTrue('Y' in openRange) assertFalse('Z' in openRange) - assertTrue(('A' until '\u0000').isEmpty()) + assertTrue(('A' until Char.MIN_VALUE).isEmpty()) } @Test fun doubleRange() {