Files
kotlin/compiler/testData/codegen/box/secondaryConstructors/basicNoPrimaryManySinks.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

36 lines
748 B
Kotlin
Vendored

var sideEffects: String = ""
class A {
var prop: String = ""
init {
sideEffects += prop + "first"
}
constructor(x: String) {
prop = x
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int) {
prop += "$x#int"
sideEffects += "#fourth"
}
}
fun box(): String {
val a1 = A("abc")
if (a1.prop != "abc") return "fail1: ${a1.prop}"
if (sideEffects != "first#second#third") return "fail1-sideEffects: ${sideEffects}"
sideEffects = ""
val a2 = A(123)
if (a2.prop != "123#int") return "fail2: ${a2.prop}"
if (sideEffects != "first#second#fourth") return "fail2-sideEffects: ${sideEffects}"
return "OK"
}