Files
kotlin-fork/compiler/testData/codegen/box/inlineClasses/secondaryConstructorsWithBody.kt
T
Evgeniy.Zhelenskiy 8c748bfea4 [IR] Add more tests for inline/value classes secondary constructors
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-55333
2023-04-17 12:10:14 +00:00

38 lines
876 B
Kotlin
Vendored

// LANGUAGE: +ValueClassesSecondaryConstructorWithBody
// IGNORE_BACKEND: JVM
// CHECK_BYTECODE_LISTING
// WITH_STDLIB
// FIR_IDENTICAL
// WORKS_WHEN_VALUE_CLASS
val l = mutableListOf<Any>()
OPTIONAL_JVM_INLINE_ANNOTATION
value class VC(val x: Int) {
constructor(xD: Double) : this(-xD.toInt()) {
l.add(xD)
l.add(x)
l.add(this)
l.add(xD.let { it - 1.0 }.let(fun(x: Double) = x - 1.0))
class Inner(val x: Int) {
constructor(x: Long): this(x.toInt()) {
l.add(x)
}
}
Inner(Long.MAX_VALUE)
}
init {
l.add(x)
l.add(this)
}
}
fun box(): String {
val vc = VC(1)
require(vc == VC(-1.0)) { "$vc\n${VC(-1.0)}" }
val actual = listOf(1, vc, 1, vc, -1.0, 1, vc, -3.0, Long.MAX_VALUE)
require(l == actual) { "$l\n$actual" }
return "OK"
}