From b64b96eee64da826d85e6a53a15d83ae7bc58841 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 6 Apr 2021 15:36:44 +0300 Subject: [PATCH] Deprecate Char-to-Number conversions in stdlib (JVM and JS) - Int.toChar was left non-deprecated because the replacement is not intrinsic yet. - Number.toChar was left non-deprecated because otherwise the deprecation propagates to the override, Int.toChar. KT-23451 --- .../testData/builtIns/kotlin.txt | 22 +++++++------- .../builtin-classes/default/kotlin.txt | 22 +++++++------- .../testData/builtin-classes/java6/kotlin.txt | 22 +++++++------- .../testData/builtin-classes/java8/kotlin.txt | 22 +++++++------- .../builtin-classes/newMethods/kotlin.txt | 22 +++++++------- .../pseudocodeMemoryOverhead.kt | 22 +++++++------- core/builtins/native/kotlin/Char.kt | 12 ++++++++ core/builtins/native/kotlin/Number.kt | 1 + core/builtins/native/kotlin/Primitives.kt | 10 +++++++ .../src/kotlin/ProgressionIterators.kt | 12 ++++---- core/builtins/src/kotlin/Progressions.kt | 8 ++--- core/builtins/src/kotlin/Ranges.kt | 2 +- generators/builtins/primitives.kt | 12 ++++++-- generators/builtins/progressionIterators.kt | 6 ++-- generators/builtins/progressions.kt | 12 ++++++-- generators/builtins/ranges.kt | 2 +- libraries/stdlib/api/js-v1/kotlin.kt | 22 ++++++++++++++ libraries/stdlib/api/js/kotlin.kt | 21 +++++++++++++ .../stdlib/common/src/generated/_Ranges.kt | 4 +-- libraries/stdlib/js-ir/builtins/Char.kt | 12 ++++++++ libraries/stdlib/js-ir/builtins/Primitives.kt | 7 +++++ libraries/stdlib/js-ir/runtime/long.kt | 2 ++ .../js-ir/src/generated/_CharCategories.kt | 6 ++-- .../stdlib/js-ir/src/generated/_DigitChars.kt | 2 +- .../js-ir/src/generated/_LetterChars.kt | 4 +-- .../js-ir/src/generated/_TitlecaseMappings.kt | 2 +- .../js-ir/src/generated/_WhitespaceChars.kt | 2 +- .../js/src/generated/_CharCategories.kt | 6 ++-- .../stdlib/js/src/generated/_DigitChars.kt | 2 +- .../stdlib/js/src/generated/_LetterChars.kt | 4 +-- .../js/src/generated/_TitlecaseMappings.kt | 2 +- .../js/src/generated/_WhitespaceChars.kt | 2 +- .../stdlib/js/src/kotlin/text/utf8Encoding.kt | 4 +-- libraries/stdlib/jvm/src/kotlin/io/Console.kt | 4 +-- .../stdlib/jvm/src/kotlin/text/CharJVM.kt | 2 +- .../stdlib/jvm/src/kotlin/text/StringsJVM.kt | 4 +-- libraries/stdlib/jvm/test/io/ReadWrite.kt | 2 +- .../test/samples/collections/arrays.kt | 12 ++++---- .../stdlib/samples/test/samples/text/char.kt | 4 +-- .../samples/test/samples/text/strings.kt | 18 +++++------ libraries/stdlib/src/kotlin/CharCode.kt | 1 + .../collections/AbstractCollectionsTest.kt | 6 ++-- .../stdlib/test/collections/ArraysTest.kt | 30 +++++++++---------- .../stdlib/test/collections/GroupingTest.kt | 2 +- libraries/stdlib/test/numbers/NumbersTest.kt | 4 +-- libraries/stdlib/test/text/CharTest.kt | 2 +- .../stdlib/test/text/StringEncodingTest.kt | 2 +- .../OneToManyUppercaseMappingsWriter.kt | 2 +- .../writers/LowercaseMappingsWriter.kt | 2 +- .../writers/TitlecaseMappingsWriter.kt | 2 +- .../writers/UppercaseMappingsWriter.kt | 2 +- .../string/StringLowercaseGenerator.kt | 6 ++-- .../string/StringUppercaseGenerator.kt | 2 +- .../ranges/CharCategoryTestGenerator.kt | 2 +- .../ranges/writers/CategoryRangesWriter.kt | 6 ++-- .../ranges/writers/DigitRangesWriter.kt | 2 +- .../ranges/writers/LetterRangesWriter.kt | 4 +-- .../ranges/writers/WhitespaceRangesWriter.kt | 2 +- .../src/templates/Elements.kt | 4 +-- 59 files changed, 273 insertions(+), 169 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/builtIns/kotlin.txt b/compiler/fir/analysis-tests/testData/builtIns/kotlin.txt index d2e711545e4..acb744e020f 100644 --- a/compiler/fir/analysis-tests/testData/builtIns/kotlin.txt +++ b/compiler/fir/analysis-tests/testData/builtIns/kotlin.txt @@ -200,7 +200,7 @@ public final class Byte : R|kotlin/Number|, R|kotlin/Comparable|, R public open fun toByte(): R|kotlin/Byte| - public open fun toChar(): R|kotlin/Char| + @R|kotlin/Deprecated|(message = String(Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.toInt().toChar())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public open fun toChar(): R|kotlin/Char| public open fun toDouble(): R|kotlin/Double| @@ -288,19 +288,19 @@ public final class Char : R|kotlin/Comparable|, R|java/io/Serializa public final operator fun rangeTo(other: R|kotlin/Char|): R|kotlin/ranges/CharRange| - public final fun toByte(): R|kotlin/Byte| + @R|kotlin/Deprecated|(message = String(Conversion of Char to Number is deprecated. Use Char.code property instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.code.toByte())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public final fun toByte(): R|kotlin/Byte| public final fun toChar(): R|kotlin/Char| - public final fun toDouble(): R|kotlin/Double| + @R|kotlin/Deprecated|(message = String(Conversion of Char to Number is deprecated. Use Char.code property instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.code.toDouble())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public final fun toDouble(): R|kotlin/Double| - public final fun toFloat(): R|kotlin/Float| + @R|kotlin/Deprecated|(message = String(Conversion of Char to Number is deprecated. Use Char.code property instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.code.toFloat())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public final fun toFloat(): R|kotlin/Float| - public final fun toInt(): R|kotlin/Int| + @R|kotlin/Deprecated|(message = String(Conversion of Char to Number is deprecated. Use Char.code property instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.code)) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public final fun toInt(): R|kotlin/Int| - public final fun toLong(): R|kotlin/Long| + @R|kotlin/Deprecated|(message = String(Conversion of Char to Number is deprecated. Use Char.code property instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.code.toLong())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public final fun toLong(): R|kotlin/Long| - public final fun toShort(): R|kotlin/Short| + @R|kotlin/Deprecated|(message = String(Conversion of Char to Number is deprecated. Use Char.code property instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.code.toShort())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public final fun toShort(): R|kotlin/Short| private constructor(): R|kotlin/Char| @@ -486,7 +486,7 @@ public final class Double : R|kotlin/Number|, R|kotlin/Comparable @R|kotlin/Deprecated|(message = String(Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(toInt().toByte())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.3), errorSince = String(1.5)) public open fun toByte(): R|kotlin/Byte| - public open fun toChar(): R|kotlin/Char| + @R|kotlin/Deprecated|(message = String(Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.toInt().toChar())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public open fun toChar(): R|kotlin/Char| public open fun toDouble(): R|kotlin/Double| @@ -665,7 +665,7 @@ public final class Float : R|kotlin/Number|, R|kotlin/Comparable|, @R|kotlin/Deprecated|(message = String(Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(toInt().toByte())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.3), errorSince = String(1.5)) public open fun toByte(): R|kotlin/Byte| - public open fun toChar(): R|kotlin/Char| + @R|kotlin/Deprecated|(message = String(Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.toInt().toChar())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public open fun toChar(): R|kotlin/Char| public open fun toDouble(): R|kotlin/Double| @@ -976,7 +976,7 @@ public final class Long : R|kotlin/Number|, R|kotlin/Comparable|, R public open fun toByte(): R|kotlin/Byte| - public open fun toChar(): R|kotlin/Char| + @R|kotlin/Deprecated|(message = String(Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.toInt().toChar())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public open fun toChar(): R|kotlin/Char| public open fun toDouble(): R|kotlin/Double| @@ -1170,7 +1170,7 @@ public final class Short : R|kotlin/Number|, R|kotlin/Comparable|, public open fun toByte(): R|kotlin/Byte| - public open fun toChar(): R|kotlin/Char| + @R|kotlin/Deprecated|(message = String(Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.), replaceWith = @R|kotlin/ReplaceWith|(imports = (), expression = String(this.toInt().toChar())) ) @R|kotlin/DeprecatedSinceKotlin|(warningSince = String(1.5)) public open fun toChar(): R|kotlin/Char| public open fun toDouble(): R|kotlin/Double| diff --git a/compiler/testData/builtin-classes/default/kotlin.txt b/compiler/testData/builtin-classes/default/kotlin.txt index b0856a41990..7cdc2a911f5 100644 --- a/compiler/testData/builtin-classes/default/kotlin.txt +++ b/compiler/testData/builtin-classes/default/kotlin.txt @@ -100,7 +100,7 @@ public final class Byte : kotlin.Number, kotlin.Comparable { public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -141,13 +141,13 @@ public final class Char : kotlin.Comparable { public final operator fun minus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun plus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun rangeTo(/*0*/ other: kotlin.Char): kotlin.ranges.CharRange - public final fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toByte(): kotlin.Byte public final fun toChar(): kotlin.Char - public final fun toDouble(): kotlin.Double - public final fun toFloat(): kotlin.Float - public final fun toInt(): kotlin.Int - public final fun toLong(): kotlin.Long - public final fun toShort(): kotlin.Short + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toDouble(): kotlin.Double + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toFloat(): kotlin.Float + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toInt(): kotlin.Int + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toLong(): kotlin.Long + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toShort(): kotlin.Short public companion object Companion { /*primary*/ private constructor Companion() @@ -276,7 +276,7 @@ public final class Double : kotlin.Number, kotlin.Comparable { public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Double public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Double @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -377,7 +377,7 @@ public final class Float : kotlin.Number, kotlin.Comparable { public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Float public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Float @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -552,7 +552,7 @@ public final class Long : kotlin.Number, kotlin.Comparable { public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Long public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -664,7 +664,7 @@ public final class Short : kotlin.Number, kotlin.Comparable { public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int diff --git a/compiler/testData/builtin-classes/java6/kotlin.txt b/compiler/testData/builtin-classes/java6/kotlin.txt index 83757d3e052..13171d91651 100644 --- a/compiler/testData/builtin-classes/java6/kotlin.txt +++ b/compiler/testData/builtin-classes/java6/kotlin.txt @@ -102,7 +102,7 @@ public final class Byte : kotlin.Number, kotlin.Comparable, java.io public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -144,13 +144,13 @@ public final class Char : kotlin.Comparable, java.io.Serializable { public final operator fun minus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun plus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun rangeTo(/*0*/ other: kotlin.Char): kotlin.ranges.CharRange - public final fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toByte(): kotlin.Byte public final fun toChar(): kotlin.Char - public final fun toDouble(): kotlin.Double - public final fun toFloat(): kotlin.Float - public final fun toInt(): kotlin.Int - public final fun toLong(): kotlin.Long - public final fun toShort(): kotlin.Short + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toDouble(): kotlin.Double + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toFloat(): kotlin.Float + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toInt(): kotlin.Int + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toLong(): kotlin.Long + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toShort(): kotlin.Short public companion object Companion { /*primary*/ private constructor Companion() @@ -286,7 +286,7 @@ public final class Double : kotlin.Number, kotlin.Comparable, jav public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Double public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Double @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -390,7 +390,7 @@ public final class Float : kotlin.Number, kotlin.Comparable, java. public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Float public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Float @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -567,7 +567,7 @@ public final class Long : kotlin.Number, kotlin.Comparable, java.io public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Long public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -680,7 +680,7 @@ public final class Short : kotlin.Number, kotlin.Comparable, java. public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int diff --git a/compiler/testData/builtin-classes/java8/kotlin.txt b/compiler/testData/builtin-classes/java8/kotlin.txt index 20cec0281ad..d9167db4716 100644 --- a/compiler/testData/builtin-classes/java8/kotlin.txt +++ b/compiler/testData/builtin-classes/java8/kotlin.txt @@ -102,7 +102,7 @@ public final class Byte : kotlin.Number, kotlin.Comparable, java.io public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -144,13 +144,13 @@ public final class Char : kotlin.Comparable, java.io.Serializable { public final operator fun minus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun plus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun rangeTo(/*0*/ other: kotlin.Char): kotlin.ranges.CharRange - public final fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toByte(): kotlin.Byte public final fun toChar(): kotlin.Char - public final fun toDouble(): kotlin.Double - public final fun toFloat(): kotlin.Float - public final fun toInt(): kotlin.Int - public final fun toLong(): kotlin.Long - public final fun toShort(): kotlin.Short + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toDouble(): kotlin.Double + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toFloat(): kotlin.Float + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toInt(): kotlin.Int + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toLong(): kotlin.Long + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toShort(): kotlin.Short public companion object Companion { /*primary*/ private constructor Companion() @@ -288,7 +288,7 @@ public final class Double : kotlin.Number, kotlin.Comparable, jav public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Double public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Double @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -392,7 +392,7 @@ public final class Float : kotlin.Number, kotlin.Comparable, java. public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Float public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Float @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -569,7 +569,7 @@ public final class Long : kotlin.Number, kotlin.Comparable, java.io public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Long public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -682,7 +682,7 @@ public final class Short : kotlin.Number, kotlin.Comparable, java. public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int diff --git a/compiler/testData/builtin-classes/newMethods/kotlin.txt b/compiler/testData/builtin-classes/newMethods/kotlin.txt index 1b632d7501b..f81e04f9b7d 100644 --- a/compiler/testData/builtin-classes/newMethods/kotlin.txt +++ b/compiler/testData/builtin-classes/newMethods/kotlin.txt @@ -102,7 +102,7 @@ public final class Byte : kotlin.Number, kotlin.Comparable, java.io public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -144,13 +144,13 @@ public final class Char : kotlin.Comparable, java.io.Serializable { public final operator fun minus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun plus(/*0*/ other: kotlin.Int): kotlin.Char public final operator fun rangeTo(/*0*/ other: kotlin.Char): kotlin.ranges.CharRange - public final fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toByte(): kotlin.Byte public final fun toChar(): kotlin.Char - public final fun toDouble(): kotlin.Double - public final fun toFloat(): kotlin.Float - public final fun toInt(): kotlin.Int - public final fun toLong(): kotlin.Long - public final fun toShort(): kotlin.Short + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toDouble(): kotlin.Double + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toFloat(): kotlin.Float + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toInt(): kotlin.Int + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toLong(): kotlin.Long + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toShort(): kotlin.Short public companion object Companion { /*primary*/ private constructor Companion() @@ -286,7 +286,7 @@ public final class Double : kotlin.Number, kotlin.Comparable, jav public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Double public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Double @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -390,7 +390,7 @@ public final class Float : kotlin.Number, kotlin.Comparable, java. public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Float public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Float @kotlin.Deprecated(message = "Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", replaceWith = kotlin.ReplaceWith(expression = "toInt().toByte()", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -567,7 +567,7 @@ public final class Long : kotlin.Number, kotlin.Comparable, java.io public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Long public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int @@ -680,7 +680,7 @@ public final class Short : kotlin.Number, kotlin.Comparable, java. public final operator fun times(/*0*/ other: kotlin.Long): kotlin.Long public final operator fun times(/*0*/ other: kotlin.Short): kotlin.Int public open override /*1*/ fun toByte(): kotlin.Byte - public open override /*1*/ fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override /*1*/ fun toChar(): kotlin.Char public open override /*1*/ fun toDouble(): kotlin.Double public open override /*1*/ fun toFloat(): kotlin.Float public open override /*1*/ fun toInt(): kotlin.Int diff --git a/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt index a50f401fa3a..689fab0b6ff 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt @@ -42,23 +42,23 @@ private val unaryOperations: HashMap, Pair a.toInt() }, emptyUnaryFun), unaryOperation(BYTE, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), unaryOperation(BYTE, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), - unaryOperation(BYTE, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(BYTE, "toChar", { a -> a.toChar() }, emptyUnaryFun), unaryOperation(BYTE, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(BYTE, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), unaryOperation(BYTE, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), unaryOperation(BYTE, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), unaryOperation(BYTE, "toShort", { a -> a.toShort() }, emptyUnaryFun), unaryOperation(BYTE, "toByte", { a -> a.toByte() }, emptyUnaryFun), - unaryOperation(CHAR, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(CHAR, "toInt", { a -> a.toInt() }, emptyUnaryFun), unaryOperation(CHAR, "toChar", { a -> a.toChar() }, emptyUnaryFun), - unaryOperation(CHAR, "toLong", { a -> a.toLong() }, emptyUnaryFun), - unaryOperation(CHAR, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), - unaryOperation(CHAR, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), - unaryOperation(CHAR, "toShort", { a -> a.toShort() }, emptyUnaryFun), - unaryOperation(CHAR, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(CHAR, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(CHAR, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(CHAR, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(CHAR, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(CHAR, "toByte", { a -> a.toByte() }, emptyUnaryFun), unaryOperation(DOUBLE, "toInt", { a -> a.toInt() }, emptyUnaryFun), unaryOperation(DOUBLE, "minus", { a -> a.unaryMinus() }, emptyUnaryFun), - unaryOperation(DOUBLE, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toChar", { a -> a.toChar() }, emptyUnaryFun), unaryOperation(DOUBLE, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(DOUBLE, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), unaryOperation(DOUBLE, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), @@ -67,7 +67,7 @@ private val unaryOperations: HashMap, Pair a.toByte() }, emptyUnaryFun), unaryOperation(FLOAT, "toInt", { a -> a.toInt() }, emptyUnaryFun), unaryOperation(FLOAT, "minus", { a -> a.unaryMinus() }, emptyUnaryFun), - unaryOperation(FLOAT, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(FLOAT, "toChar", { a -> a.toChar() }, emptyUnaryFun), unaryOperation(FLOAT, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(FLOAT, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), unaryOperation(FLOAT, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), @@ -90,13 +90,13 @@ private val unaryOperations: HashMap, Pair a.inv() }, emptyUnaryFun), unaryOperation(LONG, "toInt", { a -> a.toInt() }, emptyUnaryFun), unaryOperation(LONG, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), - unaryOperation(LONG, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(LONG, "toChar", { a -> a.toChar() }, emptyUnaryFun), unaryOperation(LONG, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(LONG, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), unaryOperation(LONG, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), unaryOperation(SHORT, "toInt", { a -> a.toInt() }, emptyUnaryFun), unaryOperation(SHORT, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), - unaryOperation(SHORT, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(SHORT, "toChar", { a -> a.toChar() }, emptyUnaryFun), unaryOperation(SHORT, "toLong", { a -> a.toLong() }, emptyUnaryFun), unaryOperation(SHORT, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), unaryOperation(SHORT, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), diff --git a/core/builtins/native/kotlin/Char.kt b/core/builtins/native/kotlin/Char.kt index e2d328fe74c..f642ea93f67 100644 --- a/core/builtins/native/kotlin/Char.kt +++ b/core/builtins/native/kotlin/Char.kt @@ -47,18 +47,30 @@ public class Char private constructor() : Comparable { public operator fun rangeTo(other: Char): CharRange /** Returns the value of this character as a `Byte`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toByte()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toByte(): Byte /** Returns the value of this character as a `Char`. */ public fun toChar(): Char /** Returns the value of this character as a `Short`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toShort()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toShort(): Short /** Returns the value of this character as a `Int`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toInt(): Int /** Returns the value of this character as a `Long`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toLong()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toLong(): Long /** Returns the value of this character as a `Float`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toFloat()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toFloat(): Float /** Returns the value of this character as a `Double`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toDouble()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toDouble(): Double companion object { diff --git a/core/builtins/native/kotlin/Number.kt b/core/builtins/native/kotlin/Number.kt index 49da583bf4b..cc57b35b91b 100644 --- a/core/builtins/native/kotlin/Number.kt +++ b/core/builtins/native/kotlin/Number.kt @@ -43,6 +43,7 @@ public abstract class Number { /** * Returns the [Char] with the numeric value equal to this number, truncated to 16 bits if appropriate. */ +// @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) public abstract fun toChar(): Char /** diff --git a/core/builtins/native/kotlin/Primitives.kt b/core/builtins/native/kotlin/Primitives.kt index 0c3b456604a..cc164d0f333 100644 --- a/core/builtins/native/kotlin/Primitives.kt +++ b/core/builtins/native/kotlin/Primitives.kt @@ -201,6 +201,8 @@ public class Byte private constructor() : Number(), Comparable { * The least significant 8 bits of the resulting `Char` code are the same as the bits of this `Byte` value, * whereas the most significant 8 bits are filled with the sign bit of this value. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** * Converts this [Byte] value to [Short]. @@ -442,6 +444,8 @@ public class Short private constructor() : Number(), Comparable { * The resulting `Char` code is equal to this value reinterpreted as an unsigned number, * i.e. it has the same binary representation as this `Short`. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** Returns this value. */ public override fun toShort(): Short @@ -982,6 +986,8 @@ public class Long private constructor() : Number(), Comparable { * * The resulting `Char` code is represented by the least significant 16 bits of this `Long` value. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** * Converts this [Long] value to [Short]. @@ -1225,6 +1231,8 @@ public class Float private constructor() : Number(), Comparable { * * The resulting `Char` value is equal to `this.toInt().toChar()`. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** * Converts this [Float] value to [Short]. @@ -1464,6 +1472,8 @@ public class Double private constructor() : Number(), Comparable { * * The resulting `Char` value is equal to `this.toInt().toChar()`. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** * Converts this [Double] value to [Short]. diff --git a/core/builtins/src/kotlin/ProgressionIterators.kt b/core/builtins/src/kotlin/ProgressionIterators.kt index 3ef513d272c..914191d12c1 100644 --- a/core/builtins/src/kotlin/ProgressionIterators.kt +++ b/core/builtins/src/kotlin/ProgressionIterators.kt @@ -12,9 +12,9 @@ package kotlin.ranges * @property step the number by which the value is incremented on each step. */ internal class CharProgressionIterator(first: Char, last: Char, val step: Int) : CharIterator() { - private val finalElement = last.toInt() + private val finalElement: Int = last.code private var hasNext: Boolean = if (step > 0) first <= last else first >= last - private var next = if (hasNext) first.toInt() else finalElement + private var next: Int = if (hasNext) first.code else finalElement override fun hasNext(): Boolean = hasNext @@ -36,9 +36,9 @@ internal class CharProgressionIterator(first: Char, last: Char, val step: Int) : * @property step the number by which the value is incremented on each step. */ internal class IntProgressionIterator(first: Int, last: Int, val step: Int) : IntIterator() { - private val finalElement = last + private val finalElement: Int = last private var hasNext: Boolean = if (step > 0) first <= last else first >= last - private var next = if (hasNext) first else finalElement + private var next: Int = if (hasNext) first else finalElement override fun hasNext(): Boolean = hasNext @@ -60,9 +60,9 @@ internal class IntProgressionIterator(first: Int, last: Int, val step: Int) : In * @property step the number by which the value is incremented on each step. */ internal class LongProgressionIterator(first: Long, last: Long, val step: Long) : LongIterator() { - private val finalElement = last + private val finalElement: Long = last private var hasNext: Boolean = if (step > 0) first <= last else first >= last - private var next = if (hasNext) first else finalElement + private var next: Long = if (hasNext) first else finalElement override fun hasNext(): Boolean = hasNext diff --git a/core/builtins/src/kotlin/Progressions.kt b/core/builtins/src/kotlin/Progressions.kt index 9e8bc8b9f66..85efeed0949 100644 --- a/core/builtins/src/kotlin/Progressions.kt +++ b/core/builtins/src/kotlin/Progressions.kt @@ -32,7 +32,7 @@ public open class CharProgression /** * The last element in the progression. */ - public val last: Char = getProgressionLastElement(start.toInt(), endInclusive.toInt(), step).toChar() + public val last: Char = getProgressionLastElement(start.code, endInclusive.code, step).toChar() /** * The step of the progression. @@ -54,7 +54,7 @@ public open class CharProgression first == other.first && last == other.last && step == other.step) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * (31 * first.toInt() + last.toInt()) + step) + if (isEmpty()) -1 else (31 * (31 * first.code + last.code) + step) override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}" @@ -94,7 +94,7 @@ public open class IntProgression /** * The last element in the progression. */ - public val last: Int = getProgressionLastElement(start.toInt(), endInclusive.toInt(), step).toInt() + public val last: Int = getProgressionLastElement(start, endInclusive, step) /** * The step of the progression. @@ -156,7 +156,7 @@ public open class LongProgression /** * The last element in the progression. */ - public val last: Long = getProgressionLastElement(start.toLong(), endInclusive.toLong(), step).toLong() + public val last: Long = getProgressionLastElement(start, endInclusive, step) /** * The step of the progression. diff --git a/core/builtins/src/kotlin/Ranges.kt b/core/builtins/src/kotlin/Ranges.kt index 661acaa125c..d9941ae1afa 100644 --- a/core/builtins/src/kotlin/Ranges.kt +++ b/core/builtins/src/kotlin/Ranges.kt @@ -28,7 +28,7 @@ public class CharRange(start: Char, endInclusive: Char) : CharProgression(start, first == other.first && last == other.last) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * first.toInt() + last.toInt()) + if (isEmpty()) -1 else (31 * first.code + last.code) override fun toString(): String = "$first..$last" diff --git a/generators/builtins/primitives.kt b/generators/builtins/primitives.kt index 2fc5a0fa4b8..e111d1efa2b 100644 --- a/generators/builtins/primitives.kt +++ b/generators/builtins/primitives.kt @@ -394,10 +394,14 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { } private fun generateConversions(kind: PrimitiveType) { - fun isConversionDeprecated(otherKind: PrimitiveType): Boolean { + fun isFpToIntConversionDeprecated(otherKind: PrimitiveType): Boolean { return kind in PrimitiveType.floatingPoint && otherKind in listOf(PrimitiveType.BYTE, PrimitiveType.SHORT) } + fun isCharConversionDeprecated(otherKind: PrimitiveType): Boolean { + return kind != PrimitiveType.INT && otherKind == PrimitiveType.CHAR + } + val thisName = kind.capitalized for (otherKind in PrimitiveType.exceptBoolean) { val otherName = otherKind.capitalized @@ -422,10 +426,14 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { } out.println(doc) - if (isConversionDeprecated(otherKind)) { + if (isFpToIntConversionDeprecated(otherKind)) { out.println(" @Deprecated(\"Unclear conversion. To achieve the same result convert to Int explicitly and then to $otherName.\", ReplaceWith(\"toInt().to$otherName()\"))") out.println(" @DeprecatedSinceKotlin(warningSince = \"1.3\", errorSince = \"1.5\")") } + if (isCharConversionDeprecated(otherKind)) { + out.println(" @Deprecated(\"Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.\", ReplaceWith(\"this.toInt().toChar()\"))") + out.println(" @DeprecatedSinceKotlin(warningSince = \"1.5\")") + } out.println(" public override fun to$otherName(): $otherName") } diff --git a/generators/builtins/progressionIterators.kt b/generators/builtins/progressionIterators.kt index 99ec608bf34..accce30d7b7 100644 --- a/generators/builtins/progressionIterators.kt +++ b/generators/builtins/progressionIterators.kt @@ -27,7 +27,7 @@ fun integerProgressionIterator(kind: ProgressionKind): String { val incrementType = progressionIncrementType(kind) val (toInt, toType) = when (kind) { - CHAR -> ".toInt()" to ".to$t()" + CHAR -> ".code" to ".toChar()" else -> "" to "" } @@ -36,9 +36,9 @@ fun integerProgressionIterator(kind: ProgressionKind): String { * @property step the number by which the value is incremented on each step. */ internal class ${t}ProgressionIterator(first: $t, last: $t, val step: $incrementType) : ${t}Iterator() { - private val finalElement = last$toInt + private val finalElement: $incrementType = last$toInt private var hasNext: Boolean = if (step > 0) first <= last else first >= last - private var next = if (hasNext) first$toInt else finalElement + private var next: $incrementType = if (hasNext) first$toInt else finalElement override fun hasNext(): Boolean = hasNext diff --git a/generators/builtins/progressions.kt b/generators/builtins/progressions.kt index b93a66a7e5d..ec15af478ed 100644 --- a/generators/builtins/progressions.kt +++ b/generators/builtins/progressions.kt @@ -42,12 +42,20 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) { val hashCode = "=\n" + when (kind) { CHAR -> - " if (isEmpty()) -1 else (31 * (31 * first.toInt() + last.toInt()) + step)" + " if (isEmpty()) -1 else (31 * (31 * first.code + last.code) + step)" INT -> " if (isEmpty()) -1 else (31 * (31 * first + last) + step)" LONG -> " if (isEmpty()) -1 else (31 * (31 * ${hashLong("first")} + ${hashLong("last")}) + ${hashLong("step")}).toInt()" } + val elementToIncrement = when (kind) { + CHAR -> ".code" + else -> "" + } + val incrementToElement = when (kind) { + CHAR -> ".toChar()" + else -> "" + } out.println( """/** @@ -73,7 +81,7 @@ public open class $progression /** * The last element in the progression. */ - public val last: $t = getProgressionLastElement(start.to$incrementType(), endInclusive.to$incrementType(), step).to$t() + public val last: $t = getProgressionLastElement(start$elementToIncrement, endInclusive$elementToIncrement, step)$incrementToElement /** * The step of the progression. diff --git a/generators/builtins/ranges.kt b/generators/builtins/ranges.kt index 036aaa66a17..da8c1717f5c 100644 --- a/generators/builtins/ranges.kt +++ b/generators/builtins/ranges.kt @@ -39,7 +39,7 @@ class GenerateRanges(out: PrintWriter) : BuiltInsSourceGenerator(out) { val hashCode = when (kind) { CHAR -> "=\n" + - " if (isEmpty()) -1 else (31 * first.toInt() + last.toInt())" + " if (isEmpty()) -1 else (31 * first.code + last.code)" INT -> "=\n" + " if (isEmpty()) -1 else (31 * first + last)" LONG -> "=\n" + diff --git a/libraries/stdlib/api/js-v1/kotlin.kt b/libraries/stdlib/api/js-v1/kotlin.kt index b72fda66558..24577201d4d 100644 --- a/libraries/stdlib/api/js-v1/kotlin.kt +++ b/libraries/stdlib/api/js-v1/kotlin.kt @@ -1021,6 +1021,8 @@ public final class Byte : kotlin.Number, kotlin.Comparable { public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -1079,18 +1081,30 @@ public final class Char : kotlin.Comparable { public final operator fun rangeTo(other: kotlin.Char): kotlin.ranges.CharRange + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toByte(): kotlin.Byte public final fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toDouble(): kotlin.Double + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toFloat(): kotlin.Float + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toInt(): kotlin.Int + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toLong(): kotlin.Long + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toShort(): kotlin.Short public companion object of Char { @@ -1315,6 +1329,8 @@ public final class Double : kotlin.Number, kotlin.Comparable { @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -1552,6 +1568,8 @@ public final class Float : kotlin.Number, kotlin.Comparable { @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -1933,6 +1951,8 @@ public final class Long : kotlin.Number, kotlin.Comparable { public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -2254,6 +2274,8 @@ public final class Short : kotlin.Number, kotlin.Comparable { public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) +/*∆*/ @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double diff --git a/libraries/stdlib/api/js/kotlin.kt b/libraries/stdlib/api/js/kotlin.kt index cdff15dd001..2afebd8fd13 100644 --- a/libraries/stdlib/api/js/kotlin.kt +++ b/libraries/stdlib/api/js/kotlin.kt @@ -987,6 +987,8 @@ public final class Byte : kotlin.Number, kotlin.Comparable { public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -1055,18 +1057,30 @@ public final class Char : kotlin.Comparable { public final operator fun rangeTo(other: kotlin.Char): kotlin.ranges.CharRange + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toByte(): kotlin.Byte public final fun toChar(): kotlin.Char + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toDouble(): kotlin.Double + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toFloat(): kotlin.Float + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toInt(): kotlin.Int + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toLong(): kotlin.Long + @kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final fun toShort(): kotlin.Short /*∆*/ @kotlin.js.JsName(name = "toString") @@ -1290,6 +1304,8 @@ public final class Double : kotlin.Number, kotlin.Comparable { @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -1531,6 +1547,8 @@ public final class Float : kotlin.Number, kotlin.Comparable { @kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3") public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -1921,6 +1939,8 @@ public final class Long : kotlin.Number, kotlin.Comparable { public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) + @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double @@ -2248,6 +2268,7 @@ public final class Short : kotlin.Number, kotlin.Comparable { public open override fun toByte(): kotlin.Byte + @kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {})) public open override fun toChar(): kotlin.Char public open override fun toDouble(): kotlin.Double diff --git a/libraries/stdlib/common/src/generated/_Ranges.kt b/libraries/stdlib/common/src/generated/_Ranges.kt index b20bb6b12a3..bca701b4891 100644 --- a/libraries/stdlib/common/src/generated/_Ranges.kt +++ b/libraries/stdlib/common/src/generated/_Ranges.kt @@ -84,7 +84,7 @@ public fun LongRange.random(random: Random): Long { @SinceKotlin("1.3") public fun CharRange.random(random: Random): Char { try { - return random.nextInt(first.toInt(), last.toInt() + 1).toChar() + return random.nextInt(first.code, last.code + 1).toChar() } catch(e: IllegalArgumentException) { throw NoSuchElementException(e.message) } @@ -150,7 +150,7 @@ public fun LongRange.randomOrNull(random: Random): Long? { public fun CharRange.randomOrNull(random: Random): Char? { if (isEmpty()) return null - return random.nextInt(first.toInt(), last.toInt() + 1).toChar() + return random.nextInt(first.code, last.code + 1).toChar() } /** diff --git a/libraries/stdlib/js-ir/builtins/Char.kt b/libraries/stdlib/js-ir/builtins/Char.kt index 86db9810eba..3c5b55a6284 100644 --- a/libraries/stdlib/js-ir/builtins/Char.kt +++ b/libraries/stdlib/js-ir/builtins/Char.kt @@ -41,18 +41,30 @@ constructor(code: UShort) : Comparable { public operator fun rangeTo(other: Char): CharRange = CharRange(this, other) /** Returns the value of this character as a `Byte`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toByte()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toByte(): Byte = value.toByte() /** Returns the value of this character as a `Char`. */ public fun toChar(): Char = this /** Returns the value of this character as a `Short`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toShort()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toShort(): Short = value.toShort() /** Returns the value of this character as a `Int`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toInt(): Int = value /** Returns the value of this character as a `Long`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toLong()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toLong(): Long = value.toLong() /** Returns the value of this character as a `Float`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toFloat()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toFloat(): Float = value.toFloat() /** Returns the value of this character as a `Double`. */ + @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toDouble()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public fun toDouble(): Double = value.toDouble() override fun equals(other: Any?): Boolean { diff --git a/libraries/stdlib/js-ir/builtins/Primitives.kt b/libraries/stdlib/js-ir/builtins/Primitives.kt index d8225b60eda..f7fc205d7cf 100644 --- a/libraries/stdlib/js-ir/builtins/Primitives.kt +++ b/libraries/stdlib/js-ir/builtins/Primitives.kt @@ -202,6 +202,8 @@ public class Byte private constructor() : Number(), Comparable { * The least significant 8 bits of the resulting `Char` code are the same as the bits of this `Byte` value, * whereas the most significant 8 bits are filled with the sign bit of this value. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** * Converts this [Byte] value to [Short]. @@ -447,6 +449,7 @@ public class Short private constructor() : Number(), Comparable { * The resulting `Char` code is equal to this value reinterpreted as an unsigned number, * i.e. it has the same binary representation as this `Short`. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) public override fun toChar(): Char /** Returns this value. */ public override fun toShort(): Short @@ -966,6 +969,8 @@ public class Float private constructor() : Number(), Comparable { * * The resulting `Char` value is equal to `this.toInt().toChar()`. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** * Converts this [Float] value to [Short]. @@ -1210,6 +1215,8 @@ public class Double private constructor() : Number(), Comparable { * * The resulting `Char` value is equal to `this.toInt().toChar()`. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char /** * Converts this [Double] value to [Short]. diff --git a/libraries/stdlib/js-ir/runtime/long.kt b/libraries/stdlib/js-ir/runtime/long.kt index 3c3ce7f6788..3c8db977c1d 100644 --- a/libraries/stdlib/js-ir/runtime/long.kt +++ b/libraries/stdlib/js-ir/runtime/long.kt @@ -262,6 +262,8 @@ public class Long internal constructor( public fun inv(): Long = Long(low.inv(), high.inv()) public override fun toByte(): Byte = low.toByte() + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") public override fun toChar(): Char = low.toChar() public override fun toShort(): Short = low.toShort() public override fun toInt(): Int = low diff --git a/libraries/stdlib/js-ir/src/generated/_CharCategories.kt b/libraries/stdlib/js-ir/src/generated/_CharCategories.kt index c4f7a9bd022..6e6bb647a07 100644 --- a/libraries/stdlib/js-ir/src/generated/_CharCategories.kt +++ b/libraries/stdlib/js-ir/src/generated/_CharCategories.kt @@ -19,7 +19,7 @@ private object Category { val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" val fromBase64 = IntArray(128) for (i in toBase64.indices) { - fromBase64[toBase64[i].toInt()] = i + fromBase64[toBase64[i].code] = i } // rangeStartDiff.length = 1482 @@ -54,7 +54,7 @@ private fun categoryValueFrom(code: Int, ch: Int): Int { * Returns the Unicode general category of this character as an Int. */ internal fun Char.getCategoryValue(): Int { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange(Category.decodedRangeStart, ch) val start = Category.decodedRangeStart[index] @@ -70,7 +70,7 @@ internal fun decodeVarLenBase64(base64: String, fromBase64: IntArray, resultLeng var int = 0 var shift = 0 for (char in base64) { - val sixBit = fromBase64[char.toInt()] + val sixBit = fromBase64[char.code] int = int or ((sixBit and 0x1f) shl shift) if (sixBit < 0x20) { result[index++] = int diff --git a/libraries/stdlib/js-ir/src/generated/_DigitChars.kt b/libraries/stdlib/js-ir/src/generated/_DigitChars.kt index 40eac212ea2..1e50f993c0a 100644 --- a/libraries/stdlib/js-ir/src/generated/_DigitChars.kt +++ b/libraries/stdlib/js-ir/src/generated/_DigitChars.kt @@ -40,7 +40,7 @@ internal fun binarySearchRange(array: IntArray, needle: Int): Int { * Returns `true` if this character is a digit. */ internal fun Char.isDigitImpl(): Boolean { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange(Digit.rangeStart, ch) val high = Digit.rangeStart[index] + 9 return ch <= high diff --git a/libraries/stdlib/js-ir/src/generated/_LetterChars.kt b/libraries/stdlib/js-ir/src/generated/_LetterChars.kt index ba9f83e77c1..6fa6dd97d75 100644 --- a/libraries/stdlib/js-ir/src/generated/_LetterChars.kt +++ b/libraries/stdlib/js-ir/src/generated/_LetterChars.kt @@ -20,7 +20,7 @@ private object Letter { val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" val fromBase64 = IntArray(128) for (i in toBase64.indices) { - fromBase64[toBase64[i].toInt()] = i + fromBase64[toBase64[i].code] = i } // rangeStartDiff.length = 356 @@ -72,7 +72,7 @@ internal fun Char.isUpperCaseImpl(): Boolean { * - `0` otherwise. */ private fun Char.getLetterType(): Int { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange(Letter.decodedRangeStart, ch) val rangeStart = Letter.decodedRangeStart[index] diff --git a/libraries/stdlib/js-ir/src/generated/_TitlecaseMappings.kt b/libraries/stdlib/js-ir/src/generated/_TitlecaseMappings.kt index f5c60fa79bc..a6ad6ae2bad 100644 --- a/libraries/stdlib/js-ir/src/generated/_TitlecaseMappings.kt +++ b/libraries/stdlib/js-ir/src/generated/_TitlecaseMappings.kt @@ -13,7 +13,7 @@ package kotlin.text // 4 ranges totally @OptIn(ExperimentalStdlibApi::class) internal fun Char.titlecaseCharImpl(): Char { - val code = this.toInt() + val code = this.code // Letters repeating sequence and code of the Lt is a multiple of 3, e.g. <DŽ, Dž, dž> if (code in 0x01c4..0x01cc || code in 0x01f1..0x01f3) { return (3 * ((code + 1) / 3)).toChar() diff --git a/libraries/stdlib/js-ir/src/generated/_WhitespaceChars.kt b/libraries/stdlib/js-ir/src/generated/_WhitespaceChars.kt index fe55745b8bd..5ab0a1420d0 100644 --- a/libraries/stdlib/js-ir/src/generated/_WhitespaceChars.kt +++ b/libraries/stdlib/js-ir/src/generated/_WhitespaceChars.kt @@ -15,7 +15,7 @@ package kotlin.text * Returns `true` if this character is a whitespace. */ internal fun Char.isWhitespaceImpl(): Boolean { - val ch = this.toInt() + val ch = this.code return ch in 0x0009..0x000d || ch in 0x001c..0x0020 || ch == 0x00a0 diff --git a/libraries/stdlib/js/src/generated/_CharCategories.kt b/libraries/stdlib/js/src/generated/_CharCategories.kt index c4f7a9bd022..6e6bb647a07 100644 --- a/libraries/stdlib/js/src/generated/_CharCategories.kt +++ b/libraries/stdlib/js/src/generated/_CharCategories.kt @@ -19,7 +19,7 @@ private object Category { val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" val fromBase64 = IntArray(128) for (i in toBase64.indices) { - fromBase64[toBase64[i].toInt()] = i + fromBase64[toBase64[i].code] = i } // rangeStartDiff.length = 1482 @@ -54,7 +54,7 @@ private fun categoryValueFrom(code: Int, ch: Int): Int { * Returns the Unicode general category of this character as an Int. */ internal fun Char.getCategoryValue(): Int { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange(Category.decodedRangeStart, ch) val start = Category.decodedRangeStart[index] @@ -70,7 +70,7 @@ internal fun decodeVarLenBase64(base64: String, fromBase64: IntArray, resultLeng var int = 0 var shift = 0 for (char in base64) { - val sixBit = fromBase64[char.toInt()] + val sixBit = fromBase64[char.code] int = int or ((sixBit and 0x1f) shl shift) if (sixBit < 0x20) { result[index++] = int diff --git a/libraries/stdlib/js/src/generated/_DigitChars.kt b/libraries/stdlib/js/src/generated/_DigitChars.kt index 40eac212ea2..1e50f993c0a 100644 --- a/libraries/stdlib/js/src/generated/_DigitChars.kt +++ b/libraries/stdlib/js/src/generated/_DigitChars.kt @@ -40,7 +40,7 @@ internal fun binarySearchRange(array: IntArray, needle: Int): Int { * Returns `true` if this character is a digit. */ internal fun Char.isDigitImpl(): Boolean { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange(Digit.rangeStart, ch) val high = Digit.rangeStart[index] + 9 return ch <= high diff --git a/libraries/stdlib/js/src/generated/_LetterChars.kt b/libraries/stdlib/js/src/generated/_LetterChars.kt index ba9f83e77c1..6fa6dd97d75 100644 --- a/libraries/stdlib/js/src/generated/_LetterChars.kt +++ b/libraries/stdlib/js/src/generated/_LetterChars.kt @@ -20,7 +20,7 @@ private object Letter { val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" val fromBase64 = IntArray(128) for (i in toBase64.indices) { - fromBase64[toBase64[i].toInt()] = i + fromBase64[toBase64[i].code] = i } // rangeStartDiff.length = 356 @@ -72,7 +72,7 @@ internal fun Char.isUpperCaseImpl(): Boolean { * - `0` otherwise. */ private fun Char.getLetterType(): Int { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange(Letter.decodedRangeStart, ch) val rangeStart = Letter.decodedRangeStart[index] diff --git a/libraries/stdlib/js/src/generated/_TitlecaseMappings.kt b/libraries/stdlib/js/src/generated/_TitlecaseMappings.kt index f5c60fa79bc..a6ad6ae2bad 100644 --- a/libraries/stdlib/js/src/generated/_TitlecaseMappings.kt +++ b/libraries/stdlib/js/src/generated/_TitlecaseMappings.kt @@ -13,7 +13,7 @@ package kotlin.text // 4 ranges totally @OptIn(ExperimentalStdlibApi::class) internal fun Char.titlecaseCharImpl(): Char { - val code = this.toInt() + val code = this.code // Letters repeating sequence and code of the Lt is a multiple of 3, e.g. <DŽ, Dž, dž> if (code in 0x01c4..0x01cc || code in 0x01f1..0x01f3) { return (3 * ((code + 1) / 3)).toChar() diff --git a/libraries/stdlib/js/src/generated/_WhitespaceChars.kt b/libraries/stdlib/js/src/generated/_WhitespaceChars.kt index fe55745b8bd..5ab0a1420d0 100644 --- a/libraries/stdlib/js/src/generated/_WhitespaceChars.kt +++ b/libraries/stdlib/js/src/generated/_WhitespaceChars.kt @@ -15,7 +15,7 @@ package kotlin.text * Returns `true` if this character is a whitespace. */ internal fun Char.isWhitespaceImpl(): Boolean { - val ch = this.toInt() + val ch = this.code return ch in 0x0009..0x000d || ch in 0x001c..0x0020 || ch == 0x00a0 diff --git a/libraries/stdlib/js/src/kotlin/text/utf8Encoding.kt b/libraries/stdlib/js/src/kotlin/text/utf8Encoding.kt index 51eb944458b..8912334b42f 100644 --- a/libraries/stdlib/js/src/kotlin/text/utf8Encoding.kt +++ b/libraries/stdlib/js/src/kotlin/text/utf8Encoding.kt @@ -23,7 +23,7 @@ private fun codePointFromSurrogate(string: String, high: Int, index: Int, endInd if (high !in 0xD800..0xDBFF || index >= endIndex) { return malformed(0, index, throwOnMalformed) } - val low = string[index].toInt() + val low = string[index].code if (low !in 0xDC00..0xDFFF) { return malformed(0, index, throwOnMalformed) } @@ -169,7 +169,7 @@ internal fun encodeUtf8(string: String, startIndex: Int, endIndex: Int, throwOnM var charIndex = startIndex while (charIndex < endIndex) { - val code = string[charIndex++].toInt() + val code = string[charIndex++].code when { code < 0x80 -> bytes[byteIndex++] = code.toByte() diff --git a/libraries/stdlib/jvm/src/kotlin/io/Console.kt b/libraries/stdlib/jvm/src/kotlin/io/Console.kt index 1128adeffd6..987bba23499 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/Console.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/Console.kt @@ -183,7 +183,7 @@ internal object LineReader { bytes[nBytes++] = readByte.toByte() } // With "directEOL" encoding bytes are batched before being decoded all at once - if (readByte == '\n'.toInt() || nBytes == BUFFER_SIZE || !directEOL) { + if (readByte == '\n'.code || nBytes == BUFFER_SIZE || !directEOL) { // Decode the bytes that were read byteBuf.limit(nBytes) // byteBuf position is always zero charBuf.position(nChars) // charBuf limit is always BUFFER_SIZE @@ -254,7 +254,7 @@ internal object LineReader { // try decoding ASCII line separator to see if this charset (like UTF-8) encodes it directly byteBuf.clear() charBuf.clear() - byteBuf.put('\n'.toByte()) + byteBuf.put('\n'.code.toByte()) byteBuf.flip() decoder.decode(byteBuf, charBuf, false) directEOL = charBuf.position() == 1 && charBuf.get(0) == '\n' diff --git a/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt index 3a206fdbff2..49230571e54 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt @@ -288,7 +288,7 @@ public actual inline fun Char.isLowSurrogate(): Boolean = Character.isLowSurroga -internal actual fun digitOf(char: Char, radix: Int): Int = Character.digit(char.toInt(), radix) +internal actual fun digitOf(char: Char, radix: Int): Int = Character.digit(char.code, radix) /** * Checks whether the given [radix] is valid radix for string to number and number to string conversion. diff --git a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt index b7ab764e11b..8b49763998b 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt @@ -21,7 +21,7 @@ import java.util.regex.Pattern * Returns the index within this string of the first occurrence of the specified character, starting from the specified offset. */ @kotlin.internal.InlineOnly -internal actual inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).indexOf(ch.toInt(), fromIndex) +internal actual inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).indexOf(ch.code, fromIndex) /** * Returns the index within this string of the first occurrence of the specified substring, starting from the specified offset. @@ -33,7 +33,7 @@ internal actual inline fun String.nativeIndexOf(str: String, fromIndex: Int): In * Returns the index within this string of the last occurrence of the specified character. */ @kotlin.internal.InlineOnly -internal actual inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(ch.toInt(), fromIndex) +internal actual inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(ch.code, fromIndex) /** * Returns the index within this string of the last occurrence of the specified character, starting from the specified offset. diff --git a/libraries/stdlib/jvm/test/io/ReadWrite.kt b/libraries/stdlib/jvm/test/io/ReadWrite.kt index a6bc38063a0..fc57ed1fb49 100644 --- a/libraries/stdlib/jvm/test/io/ReadWrite.kt +++ b/libraries/stdlib/jvm/test/io/ReadWrite.kt @@ -84,7 +84,7 @@ class ReadWriteTest { //file.replaceText("Hello\nWorld") file.forEachBlock { arr: ByteArray, size: Int -> assertTrue(size >= 11 && size <= 12, size.toString()) - assertTrue(arr.contains('W'.toByte())) + assertTrue(arr.contains('W'.code.toByte())) } val list = ArrayList() file.forEachLine(Charsets.UTF_8, { diff --git a/libraries/stdlib/samples/test/samples/collections/arrays.kt b/libraries/stdlib/samples/test/samples/collections/arrays.kt index 2678bbaf56b..1d949be6f06 100644 --- a/libraries/stdlib/samples/test/samples/collections/arrays.kt +++ b/libraries/stdlib/samples/test/samples/collections/arrays.kt @@ -68,7 +68,7 @@ class Arrays { fun associateArrayOfPrimitives() { val charCodes = intArrayOf(72, 69, 76, 76, 79) - val byCharCode = charCodes.associate { it to it.toChar() } + val byCharCode = charCodes.associate { it to Char(it) } // 76=L only occurs once because only the last pair with the same key gets added assertPrints(byCharCode, "{72=H, 69=E, 76=L, 79=O}") @@ -79,7 +79,7 @@ class Arrays { fun associateArrayOfPrimitivesBy() { val charCodes = intArrayOf(72, 69, 76, 76, 79) - val byChar = charCodes.associateBy { it.toChar() } + val byChar = charCodes.associateBy { Char(it) } // L=76 only occurs once because only the last pair with the same key gets added assertPrints(byChar, "{H=72, E=69, L=76, O=79}") @@ -89,7 +89,7 @@ class Arrays { fun associateArrayOfPrimitivesByWithValueTransform() { val charCodes = intArrayOf(65, 65, 66, 67, 68, 69) - val byUpperCase = charCodes.associateBy({ it.toChar() }, { (it + 32).toChar() }) + val byUpperCase = charCodes.associateBy({ Char(it) }, { Char(it + 32) }) // A=a only occurs once because only the last pair with the same key gets added assertPrints(byUpperCase, "{A=a, B=b, C=c, D=d, E=e}") @@ -101,7 +101,7 @@ class Arrays { val byChar = mutableMapOf() assertTrue(byChar.isEmpty()) - charCodes.associateByTo(byChar) { it.toChar() } + charCodes.associateByTo(byChar) { Char(it) } assertTrue(byChar.isNotEmpty()) // L=76 only occurs once because only the last pair with the same key gets added @@ -113,7 +113,7 @@ class Arrays { val charCodes = intArrayOf(65, 65, 66, 67, 68, 69) val byUpperCase = mutableMapOf() - charCodes.associateByTo(byUpperCase, { it.toChar() }, { (it + 32).toChar() } ) + charCodes.associateByTo(byUpperCase, { Char(it) }, { Char(it + 32) }) // A=a only occurs once because only the last pair with the same key gets added assertPrints(byUpperCase, "{A=a, B=b, C=c, D=d, E=e}") @@ -124,7 +124,7 @@ class Arrays { val charCodes = intArrayOf(72, 69, 76, 76, 79) val byChar = mutableMapOf() - charCodes.associateTo(byChar) { it to it.toChar() } + charCodes.associateTo(byChar) { it to Char(it) } // 76=L only occurs once because only the last pair with the same key gets added assertPrints(byChar, "{72=H, 69=E, 76=L, 79=O}") diff --git a/libraries/stdlib/samples/test/samples/text/char.kt b/libraries/stdlib/samples/test/samples/text/char.kt index 777c320858f..c43f85c590e 100644 --- a/libraries/stdlib/samples/test/samples/text/char.kt +++ b/libraries/stdlib/samples/test/samples/text/char.kt @@ -35,7 +35,7 @@ class Chars { val chars = listOf('\u0000', '\u000E', '\u0009', '1', 'a') val (isoControls, notIsoControls) = chars.partition { it.isISOControl() } // some ISO-control char codes - assertPrints(isoControls.map(Char::toInt), "[0, 14, 9]") + assertPrints(isoControls.map(Char::code), "[0, 14, 9]") // non-ISO-control chars assertPrints(notIsoControls, "[1, a]") } @@ -61,7 +61,7 @@ class Chars { val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0') val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() } // whitespace char codes - assertPrints(whitespaces.map(Char::toInt), "[32, 9, 10, 160]") + assertPrints(whitespaces.map(Char::code), "[32, 9, 10, 160]") // non-whitespace chars assertPrints(notWhitespaces, "[1, a]") } diff --git a/libraries/stdlib/samples/test/samples/text/strings.kt b/libraries/stdlib/samples/test/samples/text/strings.kt index f89f0d9d015..7a53afd86e7 100644 --- a/libraries/stdlib/samples/test/samples/text/strings.kt +++ b/libraries/stdlib/samples/test/samples/text/strings.kt @@ -126,7 +126,7 @@ class Strings { fun associate() { val string = "bonne journée" // associate each character with its code - val result = string.associate { char -> char to char.toInt() } + val result = string.associate { char -> char to char.code } // notice each letter occurs only once assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}") } @@ -135,7 +135,7 @@ class Strings { fun associateBy() { val string = "bonne journée" // associate each character by its code - val result = string.associateBy { char -> char.toInt() } + val result = string.associateBy { char -> char.code } // notice each char code occurs only once assertPrints(result, "{98=b, 111=o, 110=n, 101=e, 32= , 106=j, 117=u, 114=r, 233=é}") } @@ -144,7 +144,7 @@ class Strings { fun associateByWithValueTransform() { val string = "bonne journée" // associate each character by the code of its upper case equivalent and transform the character to upper case - val result = string.associateBy({ char -> char.toUpperCase().toInt() }, { char -> char.toUpperCase() }) + val result = string.associateBy({ char -> char.uppercaseChar().code }, { char -> char.uppercaseChar() }) // notice each char code occurs only once assertPrints(result, "{66=B, 79=O, 78=N, 69=E, 32= , 74=J, 85=U, 82=R, 201=É}") } @@ -154,7 +154,7 @@ class Strings { val string = "bonne journée" // associate each character by its code val result = mutableMapOf() - string.associateByTo(result) { char -> char.toInt() } + string.associateByTo(result) { char -> char.code } // notice each char code occurs only once assertPrints(result, "{98=b, 111=o, 110=n, 101=e, 32= , 106=j, 117=u, 114=r, 233=é}") } @@ -164,7 +164,7 @@ class Strings { val string = "bonne journée" // associate each character by the code of its upper case equivalent and transform the character to upper case val result = mutableMapOf() - string.associateByTo(result, { char -> char.toUpperCase().toInt() }, { char -> char.toUpperCase() }) + string.associateByTo(result, { char -> char.uppercaseChar().code }, { char -> char.uppercaseChar() }) // notice each char code occurs only once assertPrints(result, "{66=B, 79=O, 78=N, 69=E, 32= , 74=J, 85=U, 82=R, 201=É}") } @@ -174,7 +174,7 @@ class Strings { val string = "bonne journée" // associate each character with its code val result = mutableMapOf() - string.associateTo(result) { char -> char to char.toInt() } + string.associateTo(result) { char -> char to char.code } // notice each letter occurs only once assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}") } @@ -183,7 +183,7 @@ class Strings { fun associateWith() { val string = "bonne journée" // associate each character with its code - val result = string.associateWith { char -> char.toInt() } + val result = string.associateWith { char -> char.code } // notice each letter occurs only once assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}") } @@ -193,7 +193,7 @@ class Strings { val string = "bonne journée" // associate each character with its code val result = mutableMapOf() - string.associateWithTo(result) { char -> char.toInt() } + string.associateWithTo(result) { char -> char.code } // notice each letter occurs only once assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}") } @@ -414,7 +414,7 @@ class Strings { @Sample fun map() { val string = "kotlin" - assertPrints(string.map { it.toUpperCase() }, "[K, O, T, L, I, N]") + assertPrints(string.map { it.uppercaseChar() }, "[K, O, T, L, I, N]") } @Sample diff --git a/libraries/stdlib/src/kotlin/CharCode.kt b/libraries/stdlib/src/kotlin/CharCode.kt index 3bb38509218..e7f574d8e33 100644 --- a/libraries/stdlib/src/kotlin/CharCode.kt +++ b/libraries/stdlib/src/kotlin/CharCode.kt @@ -45,4 +45,5 @@ public expect fun Char(code: UShort): Char @SinceKotlin("1.5") @WasExperimental(ExperimentalStdlibApi::class) @kotlin.internal.InlineOnly +@Suppress("DEPRECATION") public inline val Char.code: Int get() = this.toInt() diff --git a/libraries/stdlib/test/collections/AbstractCollectionsTest.kt b/libraries/stdlib/test/collections/AbstractCollectionsTest.kt index d0e0e02009b..fced3dc517f 100644 --- a/libraries/stdlib/test/collections/AbstractCollectionsTest.kt +++ b/libraries/stdlib/test/collections/AbstractCollectionsTest.kt @@ -149,16 +149,16 @@ class AbstractCollectionsTest { @Test fun abstractMutableMap() { val map = MutMap() - for (e in 'a'..'z') map[e.toString()] = e.toInt() + for (e in 'a'..'z') map[e.toString()] = e.code assertEquals(26, map.size) map.remove("a") map.keys.remove("b") map.keys.removeAll { it == "c" } - map.values.remove('d'.toInt()) + map.values.remove('d'.code) assertTrue(map.containsKey("e")) - assertTrue(map.containsValue('f'.toInt())) + assertTrue(map.containsValue('f'.code)) compare(map.storage, map) { mapBehavior() diff --git a/libraries/stdlib/test/collections/ArraysTest.kt b/libraries/stdlib/test/collections/ArraysTest.kt index 2037f47b34c..e19afefc900 100644 --- a/libraries/stdlib/test/collections/ArraysTest.kt +++ b/libraries/stdlib/test/collections/ArraysTest.kt @@ -1156,7 +1156,7 @@ class ArraysTest { assertEquals(expected, FloatArray(size) { it.toFloat() }.scan("") { acc, e -> acc + e.toInt() }) assertEquals(expected, DoubleArray(size) { it.toDouble() }.scan("") { acc, e -> acc + e.toInt() }) assertEquals( - expected.map { it.map { c -> c.toInt() % 2 == 0 }.joinToString(separator = "") }, + expected.map { it.map { c -> c.code % 2 == 0 }.joinToString(separator = "") }, BooleanArray(size) { it % 2 == 0 }.scan("") { acc, e -> acc + e } ) } @@ -1177,7 +1177,7 @@ class ArraysTest { assertEquals(expected, FloatArray(size) { it.toFloat() }.runningFold("") { acc, e -> acc + e.toInt() }) assertEquals(expected, DoubleArray(size) { it.toDouble() }.runningFold("") { acc, e -> acc + e.toInt() }) assertEquals( - expected.map { it.map { c -> c.toInt() % 2 == 0 }.joinToString(separator = "") }, + expected.map { it.map { c -> c.code % 2 == 0 }.joinToString(separator = "") }, BooleanArray(size) { it % 2 == 0 }.runningFold("") { acc, e -> acc + e } ) } @@ -1199,7 +1199,7 @@ class ArraysTest { ) assertEquals( expected, - CharArray(size) { it.toChar() }.scanIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" } + CharArray(size) { Char(it) }.scanIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.code}]" } ) assertEquals( expected, @@ -1222,7 +1222,7 @@ class ArraysTest { DoubleArray(size) { it.toDouble() }.scanIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" } ) assertEquals( - expected.map { it.map { c -> if (c.isAsciiLetter()) c.toInt() % 2 != 0 else c }.joinToString(separator = "") }, + expected.map { it.map { c -> if (c.isAsciiLetter()) c.code % 2 != 0 else c }.joinToString(separator = "") }, BooleanArray(size) { it % 2 == 0 }.scanIndexed("+") { index, acc, e -> "$acc[$index: $e]" } ) } @@ -1244,7 +1244,7 @@ class ArraysTest { ) assertEquals( expected, - CharArray(size) { it.toChar() }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" } + CharArray(size) { Char(it) }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.code}]" } ) assertEquals( expected, @@ -1267,7 +1267,7 @@ class ArraysTest { DoubleArray(size) { it.toDouble() }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" } ) assertEquals( - expected.map { it.map { c -> if (c.isAsciiLetter()) c.toInt() % 2 != 0 else c }.joinToString(separator = "") }, + expected.map { it.map { c -> if (c.isAsciiLetter()) c.code % 2 != 0 else c }.joinToString(separator = "") }, BooleanArray(size) { it % 2 == 0 }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: $e]" } ) } @@ -1288,8 +1288,8 @@ class ArraysTest { ByteArray(size) { it.toByte() }.runningReduce { acc, e -> (acc + e).toByte() } ) assertEquals( - expected.map { it.toChar() }, - CharArray(size) { it.toChar() }.runningReduce { acc, e -> acc + e.toInt() } + expected.map { Char(it) }, + CharArray(size) { Char(it) }.runningReduce { acc, e -> acc + e.code } ) assertEquals( expected.map { it.toShort() }, @@ -1332,8 +1332,8 @@ class ArraysTest { expected.map { it.toByte() }, ByteArray(size) { it.toByte() }.runningReduceIndexed { index, acc, e -> (index * (acc + e)).toByte() }) assertEquals( - expected.map { it.toChar() }, - CharArray(size) { it.toChar() }.runningReduceIndexed { index, acc, e -> (index * (acc.toInt() + e.toInt())).toChar() } + expected.map { Char(it) }, + CharArray(size) { Char(it) }.runningReduceIndexed { index, acc, e -> (index * (acc.code + e.code)).let(::Char) } ) assertEquals( expected.map { it.toShort() }, @@ -2177,7 +2177,7 @@ class ArraysTest { testShuffle(numbers.map(Int::toShort).toShortArray(), { shuffle() }, { toList() }) testShuffle(numbers.map(Int::toFloat).toFloatArray(), { shuffle() }, { toList() }) testShuffle(numbers.map(Int::toDouble).toDoubleArray(), { shuffle() }, { toList() }) - testShuffle(numbers.map(Int::toChar).toCharArray(), { shuffle() }, { toList() }) + testShuffle(numbers.map(::Char).toCharArray(), { shuffle() }, { toList() }) testShuffle(numbers.map { it % 2 == 0 }.toBooleanArray(), { shuffle() }, { toList() }) testShuffle(numbers.map(Int::toUInt).toUIntArray(), { shuffle() }, { toList() }) @@ -2207,7 +2207,7 @@ class ArraysTest { testShuffleR(numbers.map(Int::toShort).toShortArray(), { r -> shuffle(r) }, { toList() }) testShuffleR(numbers.map(Int::toFloat).toFloatArray(), { r -> shuffle(r) }, { toList() }) testShuffleR(numbers.map(Int::toDouble).toDoubleArray(), { r -> shuffle(r) }, { toList() }) - testShuffleR(numbers.map(Int::toChar).toCharArray(), { r -> shuffle(r) }, { toList() }) + testShuffleR(numbers.map(::Char).toCharArray(), { r -> shuffle(r) }, { toList() }) testShuffleR(numbers.map { it % 2 == 0 }.toBooleanArray(), { r -> shuffle(r) }, { toList() }) testShuffleR(numbers.map(Int::toUInt).toUIntArray(), { r -> shuffle(r) }, { toList() }) @@ -2244,7 +2244,7 @@ class ArraysTest { testFailures(BooleanArray(5) { it % 2 == 0 }, BooleanArray::fill, true, 5) testFailures(ByteArray(5) { it.toByte() }, ByteArray::fill, 0.toByte(), 5) - testFailures(CharArray(5) { it.toChar() }, CharArray::fill, 0.toChar(), 5) + testFailures(CharArray(5) { Char(it) }, CharArray::fill, Char(0), 5) testFailures(FloatArray(5) { it.toFloat() }, FloatArray::fill, 0.0f, 5) testFailures(DoubleArray(5) { it.toDouble() }, DoubleArray::fill, 0.0, 5) testFailures(ShortArray(5) { it.toShort() }, ShortArray::fill, 0.toShort(), 5) @@ -2278,7 +2278,7 @@ class ArraysTest { test(array, BooleanArray::fill, operations, IntArray::toBooleanArray, { this % 2 == 0 }, BooleanArray::contentEquals) test(array, ByteArray::fill, operations, IntArray::toByteArray, Int::toByte, ByteArray::contentEquals) - test(array, CharArray::fill, operations, IntArray::toCharArray, Int::toChar, CharArray::contentEquals) + test(array, CharArray::fill, operations, IntArray::toCharArray, ::Char, CharArray::contentEquals) test(array, FloatArray::fill, operations, IntArray::toFloatArray, Int::toFloat, FloatArray::contentEquals) test(array, DoubleArray::fill, operations, IntArray::toDoubleArray, Int::toDouble, DoubleArray::contentEquals) test(array, ShortArray::fill, operations, IntArray::toShortArray, Int::toShort, ShortArray::contentEquals) @@ -2297,7 +2297,7 @@ class ArraysTest { private fun IntArray.toBooleanArray() = BooleanArray(size) { get(it) % 2 == 0 } private fun IntArray.toByteArray() = ByteArray(size) { get(it).toByte() } -private fun IntArray.toCharArray() = CharArray(size) { get(it).toChar() } +private fun IntArray.toCharArray() = CharArray(size) { Char(get(it)) } private fun IntArray.toFloatArray() = FloatArray(size) { get(it).toFloat() } private fun IntArray.toDoubleArray() = DoubleArray(size) { get(it).toDouble() } private fun IntArray.toShortArray() = ShortArray(size) { get(it).toShort() } diff --git a/libraries/stdlib/test/collections/GroupingTest.kt b/libraries/stdlib/test/collections/GroupingTest.kt index 87581965fd1..7b4ab50da88 100644 --- a/libraries/stdlib/test/collections/GroupingTest.kt +++ b/libraries/stdlib/test/collections/GroupingTest.kt @@ -30,7 +30,7 @@ class GroupingTest { verifyGrouping(elements.asSequence().groupingBy(keySelector)) val charSeq = "some sequence of chars" - verifyGrouping(charSeq.groupingBy { it.toInt() }, charSeq.toList(), charSeq.map { it.toInt() }) + verifyGrouping(charSeq.groupingBy { it.code }, charSeq.toList(), charSeq.map { it.code }) } // aggregate and aggregateTo operations are not tested, but they're used in every other operation diff --git a/libraries/stdlib/test/numbers/NumbersTest.kt b/libraries/stdlib/test/numbers/NumbersTest.kt index d51172e5963..f55eb7f2b8e 100644 --- a/libraries/stdlib/test/numbers/NumbersTest.kt +++ b/libraries/stdlib/test/numbers/NumbersTest.kt @@ -128,8 +128,8 @@ class NumbersTest { } @Test fun charMinMaxValues() { - assertTrue(Char.MIN_VALUE.toInt() == 0) - assertTrue(Char.MAX_VALUE.toInt() > 0) + assertTrue(Char.MIN_VALUE.code == 0) + assertTrue(Char.MAX_VALUE.code > 0) // overflow behavior expect(Char.MIN_VALUE) { Char.MAX_VALUE + one } diff --git a/libraries/stdlib/test/text/CharTest.kt b/libraries/stdlib/test/text/CharTest.kt index e927b2b50f9..20bad350974 100644 --- a/libraries/stdlib/test/text/CharTest.kt +++ b/libraries/stdlib/test/text/CharTest.kt @@ -205,7 +205,7 @@ class CharTest { @Test fun charCategory() { for ((char, categoryCode) in charToCategory()) { - assertEquals(categoryCode, char.category.code, "char code: ${char.toInt().toString(radix = 16)}") + assertEquals(categoryCode, char.category.code, "char code: ${char.code.toString(radix = 16)}") } } diff --git a/libraries/stdlib/test/text/StringEncodingTest.kt b/libraries/stdlib/test/text/StringEncodingTest.kt index d87cdf927ce..355bd1328b3 100644 --- a/libraries/stdlib/test/text/StringEncodingTest.kt +++ b/libraries/stdlib/test/text/StringEncodingTest.kt @@ -47,7 +47,7 @@ class StringEncodingTest { // https://youtrack.jetbrains.com/issue/KT-31614 private fun string(vararg codeUnits: Int): String { - return buildString { codeUnits.forEach { append(it.toChar()) } } + return buildString { codeUnits.forEach { append(Char(it)) } } } @Test diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToMany/writers/OneToManyUppercaseMappingsWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToMany/writers/OneToManyUppercaseMappingsWriter.kt index e5287959b00..4cd8841d75f 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToMany/writers/OneToManyUppercaseMappingsWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToMany/writers/OneToManyUppercaseMappingsWriter.kt @@ -27,7 +27,7 @@ internal class OneToManyUppercaseMappingsWriter(private val strategy: RangesWrit return null } - val code = this.toInt() + val code = this.code val index = binarySearchRange(keys, code) if (keys[index] == code) { return values[index] diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/LowercaseMappingsWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/LowercaseMappingsWriter.kt index 82ec9227ff1..ae70b11437d 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/LowercaseMappingsWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/LowercaseMappingsWriter.kt @@ -46,7 +46,7 @@ internal class LowercaseMappingsWriter(private val strategy: RangesWritingStrate private fun lowercaseCharImpl(): String = """ internal fun Char.lowercaseCharImpl(): Char { - return toInt().lowercaseCodePoint().toChar() + return code.lowercaseCodePoint().toChar() } """.trimIndent() } \ No newline at end of file diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/TitlecaseMappingsWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/TitlecaseMappingsWriter.kt index f76407f2c77..86366c99270 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/TitlecaseMappingsWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/TitlecaseMappingsWriter.kt @@ -24,7 +24,7 @@ internal class TitlecaseMappingsWriter : MappingsWriter { """ @OptIn(ExperimentalStdlibApi::class) internal fun Char.titlecaseCharImpl(): Char { - val code = this.toInt() + val code = this.code // Letters repeating sequence and code of the Lt is a multiple of 3, e.g. <DŽ, Dž, dž> if (${rangeChecks(LuLtLlMappings, "code")}) { return (3 * ((code + 1) / 3)).toChar() diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/UppercaseMappingsWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/UppercaseMappingsWriter.kt index ecf63848c81..bbc2cd5865b 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/UppercaseMappingsWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/writers/UppercaseMappingsWriter.kt @@ -67,7 +67,7 @@ internal class UppercaseMappingsWriter(private val strategy: RangesWritingStrate private fun uppercaseCharImpl(): String = """ internal fun Char.uppercaseCharImpl(): Char { - return toInt().uppercaseCodePoint().toChar() + return code.uppercaseCodePoint().toChar() } """.trimIndent() } \ No newline at end of file diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringLowercaseGenerator.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringLowercaseGenerator.kt index dfaa18e18e2..435871c2783 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringLowercaseGenerator.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringLowercaseGenerator.kt @@ -94,7 +94,7 @@ internal class StringLowercaseGenerator( // Lu + Ll + Lt + Other_Lowercase + Other_Uppercase (PropList.txt of Unicode Character Database files) // Declared internal for testing internal fun Int.isCased(): Boolean { - if (this <= Char.MAX_VALUE.toInt()) { + if (this <= Char.MAX_VALUE.code) { when (toChar().getCategoryValue()) { CharCategory.UPPERCASE_LETTER.value, CharCategory.LOWERCASE_LETTER.value, @@ -110,7 +110,7 @@ internal class StringLowercaseGenerator( // Mn + Me + Cf + Lm + Sk + Word_Break=MidLetter + Word_Break=MidNumLet + Word_Break=Single_Quote (WordBreakProperty.txt of Unicode Character Database files) // Declared internal for testing internal fun Int.isCaseIgnorable(): Boolean { - if (this <= Char.MAX_VALUE.toInt()) { + if (this <= Char.MAX_VALUE.code) { when (toChar().getCategoryValue()) { CharCategory.NON_SPACING_MARK.value, CharCategory.ENCLOSING_MARK.value, @@ -133,7 +133,7 @@ internal class StringLowercaseGenerator( return Char.toCodePoint(high, low) } } - return low.toInt() + return low.code } """.trimIndent() diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringUppercaseGenerator.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringUppercaseGenerator.kt index a5c5e101071..21197abe10a 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringUppercaseGenerator.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/string/StringUppercaseGenerator.kt @@ -51,7 +51,7 @@ internal class StringUppercaseGenerator( return Char.toCodePoint(high, low) } } - return high.toInt() + return high.code } """.trimIndent() diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/CharCategoryTestGenerator.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/CharCategoryTestGenerator.kt index 584369816cc..8c6b71c9cd4 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/CharCategoryTestGenerator.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/CharCategoryTestGenerator.kt @@ -93,7 +93,7 @@ class CharCategoryTest { properties = null } - val charCode = char.toInt().toString(radix = 16).padStart(length = 4, padChar = '0') + val charCode = char.code.toString(radix = 16).padStart(length = 4, padChar = '0') val expectedCategoryCode = properties?.categoryCode ?: CharCategory.UNASSIGNED.code fun test(expected: T, actual: T, name: String) { diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/CategoryRangesWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/CategoryRangesWriter.kt index 495318777f9..65372379317 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/CategoryRangesWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/CategoryRangesWriter.kt @@ -69,7 +69,7 @@ internal open class CategoryRangesWriter(protected val strategy: RangesWritingSt * Returns the Unicode general category of this character as an Int. */ internal fun Char.getCategoryValue(): Int { - val ch = this.toInt() + val ch = this.code val index = ${indexOf("ch")} val start = ${startAt("index")} @@ -116,7 +116,7 @@ internal class VarLenBase64CategoryRangesWriter(strategy: RangesWritingStrategy) val toBase64 = "$TO_BASE64" val fromBase64 = IntArray(128) for (i in toBase64.indices) { - fromBase64[toBase64[i].toInt()] = i + fromBase64[toBase64[i].code] = i } // rangeStartDiff.length = ${base64RangeLength.length} @@ -147,7 +147,7 @@ internal class VarLenBase64CategoryRangesWriter(strategy: RangesWritingStrategy) var int = 0 var shift = 0 for (char in base64) { - val sixBit = fromBase64[char.toInt()] + val sixBit = fromBase64[char.code] int = int or ((sixBit and 0x1f) shl shift) if (sixBit < 0x20) { result[index++] = int diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/DigitRangesWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/DigitRangesWriter.kt index f35a95959ca..37732c41a65 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/DigitRangesWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/DigitRangesWriter.kt @@ -51,7 +51,7 @@ internal class DigitRangesWriter(private val strategy: RangesWritingStrategy) : * Returns `true` if this character is a digit. */ internal fun Char.isDigitImpl(): Boolean { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange($rangeStart, ch) val high = $rangeStart[index] + 9 return ch <= high diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/LetterRangesWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/LetterRangesWriter.kt index 669757f5dcc..731d5c86483 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/LetterRangesWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/LetterRangesWriter.kt @@ -81,7 +81,7 @@ internal open class LetterRangesWriter(protected val strategy: RangesWritingStra * - `0` otherwise. */ private fun Char.getLetterType(): Int { - val ch = this.toInt() + val ch = this.code val index = ${indexOf("ch")} val rangeStart = ${startAt("index")} @@ -164,7 +164,7 @@ internal class VarLenBase64LetterRangesWriter(strategy: RangesWritingStrategy) : val toBase64 = "$TO_BASE64" val fromBase64 = IntArray(128) for (i in toBase64.indices) { - fromBase64[toBase64[i].toInt()] = i + fromBase64[toBase64[i].code] = i } // rangeStartDiff.length = ${base64RangeStartDiff.length} diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/WhitespaceRangesWriter.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/WhitespaceRangesWriter.kt index db8377662bc..520b70bfd53 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/WhitespaceRangesWriter.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/writers/WhitespaceRangesWriter.kt @@ -20,7 +20,7 @@ internal class WhitespaceRangesWriter : RangesWriter { * Returns `true` if this character is a whitespace. */ internal fun Char.isWhitespaceImpl(): Boolean { - val ch = this.toInt() + val ch = this.code return $checks } """.trimIndent() diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt index 490cfa1e4e4..2c0f903397a 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt @@ -988,7 +988,7 @@ object Elements : TemplateGroupBase() { specialFor(RangesOfPrimitives) { body { val expr = when (primitive) { - PrimitiveType.Char -> "nextInt(first.toInt(), last.toInt() + 1).toChar()" + PrimitiveType.Char -> "nextInt(first.code, last.code + 1).toChar()" else -> "next$primitive(this)" } """ @@ -1033,7 +1033,7 @@ object Elements : TemplateGroupBase() { specialFor(RangesOfPrimitives) { body { val expr = when (primitive) { - PrimitiveType.Char -> "nextInt(first.toInt(), last.toInt() + 1).toChar()" + PrimitiveType.Char -> "nextInt(first.code, last.code + 1).toChar()" else -> "next$primitive(this)" } """