Files
kotlin/compiler/testData/codegen/boxWithJava/secondaryConstructors/withPrimary/WithPrimary.kt
Denis Zharkov e65382e6ec Support secondary constructors in JVM backend
There is a lot of changes about closures calculating and generating.

1. As classes can have more than one constructor each of them should
have closure arguments.

2. Captured variables set is the same for all of them.

3. Within constructors bodies/delegating calls closure parameters
should be accessed through method arguments because fields may be
not initialized yet.
2015-03-11 17:45:27 +03:00

22 lines
653 B
Kotlin
Vendored

class A(val x: String = "def_x", val y: String = "1") {
constructor(x: String, y: Int): this(x, y.toString()) {}
constructor(x: Double): this(x.toString(), "def_y") {}
override fun toString() = "$x#$y"
}
fun box(): String {
val test1 = WithPrimary.test1().toString()
if (test1 != "123#abc") return "fail1: $test1"
val test2 = WithPrimary.test2().toString()
if (test2 != "def_x#1") return "fail2: $test2"
val test3 = WithPrimary.test3().toString()
if (test3 != "123#456") return "fail3: $test3"
val test4 = WithPrimary.test4().toString()
if (test4 != "1.0#def_y") return "fail4: $test4"
return "OK"
}