Files
kotlin-fork/compiler/testData/codegen/box/inlineClasses/secondaryConstructorsInsideInlineClass.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

32 lines
764 B
Kotlin
Vendored

// WITH_STDLIB
@file:Suppress("SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS")
var global = "wrong"
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@kotlin.jvm.JvmInline
value class Foo(val x: String) {
constructor(y: Int) : this(y.toString())
constructor(z: Long) : this(z.toInt() + 1)
constructor(other: Char) : this(other.toInt().toString()) {
global = "OK"
}
constructor(a: Int, b: Int) : this((a + b).toString())
}
fun box(): String {
var f = Foo(42)
if (f.x != "42") return "Fail 1: ${f.x}"
f = Foo(43L)
if (f.x != "44") return "Fail 2: ${f.x}"
f = Foo('a')
if (f.x != "97") return "Fail 3: ${f.x}"
f = Foo(1, 2)
if (f.x != "3") return "Fail 4: ${f.x}"
return global
}