Support inline class values inside string templates through boxing
#KT-25626 Fixed #KT-25613 Open
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
inline class Augmented(val x: Int) {
|
||||
override fun toString(): String = (x + 1).toString()
|
||||
}
|
||||
|
||||
inline class AsAny(val a: Any) {
|
||||
override fun toString(): String = "AsAny: $a"
|
||||
}
|
||||
|
||||
data class AugmentedAndAsAny(val a: Augmented, val b: AsAny)
|
||||
|
||||
fun box(): String {
|
||||
val a = Augmented(0)
|
||||
val single = "$a"
|
||||
if (single != "1") return "Fail 1: $single"
|
||||
|
||||
val asAny = AsAny(42)
|
||||
val asAnyString = "$asAny"
|
||||
if (asAnyString != "AsAny: 42") return "Fail 2: $asAnyString"
|
||||
|
||||
val b = Augmented(1)
|
||||
val two = "$a and $b"
|
||||
if (two != "1 and 2") return "Fail 3: $two"
|
||||
|
||||
val d = AugmentedAndAsAny(a, asAny)
|
||||
if (d.toString() != "AugmentedAndAsAny(a=1, b=AsAny: 42)") return "Fail 4: $d"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// WITH_UNSIGNED
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS
|
||||
|
||||
const val maxUByte: UByte = 0xFFu
|
||||
|
||||
fun custom(a: Any): String {
|
||||
return "Custom: $a, isUByte: ${a is UByte}"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = custom(maxUByte)
|
||||
if (result != "Custom: 255, isUByte: true") return "Fail: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// WITH_UNSIGNED
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS
|
||||
|
||||
const val MAX_BYTE: UByte = 0xFFu
|
||||
const val HUNDRED: UByte = 100u
|
||||
|
||||
fun box(): String {
|
||||
val maxByteStringSingle = "$MAX_BYTE"
|
||||
if (maxByteStringSingle != MAX_BYTE.toString() || maxByteStringSingle != "255") return "Fail 1: $maxByteStringSingle"
|
||||
|
||||
val twoHundredUByte = "${(HUNDRED * 2u).toUByte()}"
|
||||
if (twoHundredUByte != "200") return "Fail 2: $twoHundredUByte"
|
||||
|
||||
val complexOnlyConstants = "Max: $MAX_BYTE, two hundred: $twoHundredUByte"
|
||||
if (complexOnlyConstants != "Max: 255, two hundred: 200") return "Fail 3: $complexOnlyConstants"
|
||||
|
||||
val nonConst = UByte.MAX_VALUE + 1u
|
||||
val complex = "Max UByte: $MAX_BYTE, next: $nonConst"
|
||||
if (complex != "Max UByte: 255, next: 256") return "Fail 4: $complex"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user