[Stdlib] Deprecate and make open Number.toChar()

^KT-46465 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-02-21 12:53:58 +02:00
committed by Space Team
parent 90ec84d7b7
commit a64d8e8a31
30 changed files with 399 additions and 72 deletions
@@ -0,0 +1,38 @@
// DONT_TARGET_EXACT_BACKEND: JVM
// DONT_TARGET_EXACT_BACKEND: JS
// IGNORE_BACKEND: JVM_IR, JS_IR
// KT-46465
// WITH_STDLIB
class MyNumber(val b: Boolean) : Number() {
override fun toByte(): Byte {
return toInt().toByte()
}
override fun toDouble(): Double {
return toInt().toDouble()
}
override fun toFloat(): Float {
return toInt().toFloat()
}
override fun toInt(): Int {
return if (b) { 'O'.code } else { 'K'.code }
}
override fun toLong(): Long {
return toInt().toLong()
}
override fun toShort(): Short {
return toInt().toShort()
}
}
@Suppress("DEPRECATION")
fun box(): String {
val o = MyNumber(true)
val k = MyNumber(false)
return "${o.toChar()}${k.toChar()}"
}
@@ -0,0 +1,42 @@
// DONT_TARGET_EXACT_BACKEND: JVM
// DONT_TARGET_EXACT_BACKEND: JS
// IGNORE_BACKEND: JS_IR
// KT-46465
// WITH_STDLIB
class MyNumber(val b: Boolean) : Number() {
override fun toByte(): Byte {
return toInt().toByte()
}
override fun toDouble(): Double {
return toInt().toDouble()
}
override fun toFloat(): Float {
return toInt().toFloat()
}
override fun toChar(): Char {
return super.toChar()
}
override fun toInt(): Int {
return if (b) { 'O'.code } else { 'K'.code }
}
override fun toLong(): Long {
return toInt().toLong()
}
override fun toShort(): Short {
return toInt().toShort()
}
}
@Suppress("DEPRECATION")
fun box(): String {
val o = MyNumber(true)
val k = MyNumber(false)
return "${o.toChar()}${k.toChar()}"
}
@@ -0,0 +1,41 @@
// DONT_TARGET_EXACT_BACKEND: JVM
// DONT_TARGET_EXACT_BACKEND: JS
// KT-46465
// WITH_STDLIB
interface Some {
fun toChar(): Char
}
class MyNumber(val b: Boolean) : Number() {
override fun toByte(): Byte {
return toInt().toByte()
}
override fun toDouble(): Double {
return toInt().toDouble()
}
override fun toFloat(): Float {
return toInt().toFloat()
}
override fun toInt(): Int {
return if (b) { 'O'.code } else { 'K'.code }
}
override fun toLong(): Long {
return toInt().toLong()
}
override fun toShort(): Short {
return toInt().toShort()
}
}
@Suppress("DEPRECATION")
fun box(): String {
val o = MyNumber(true)
val k = MyNumber(false)
return "${o.toChar()}${k.toChar()}"
}