Files
kotlin-fork/compiler/testData/codegen/box/secondaryConstructors/defaultArgs.kt
T
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

35 lines
964 B
Kotlin

val global = "OK"
class A {
val prop: String
constructor(arg1: String = global) {
prop = arg1
}
constructor(arg1: String = global, arg2: Long) {
prop = "$arg1#$arg2"
}
constructor(arg1: String = global, argDouble: Double, arg3: Long = 1L) {
prop = "$arg1#$argDouble#$arg3"
}
}
fun box(): String {
val a1 = A()
if (a1.prop != "OK") return "fail1: ${a1.prop}"
val a2 = A("A")
if (a2.prop != "A") return "fail2: ${a2.prop}"
val a3 = A(arg2=123)
if (a3.prop != "OK#123") return "fail3: ${a3.prop}"
val a4 = A("A", arg2=123)
if (a4.prop != "A#123") return "fail4: ${a4.prop}"
val a5 = A(argDouble=23.0)
if (a5.prop != "OK#23.0#1") return "fail5: ${a5.prop}"
val a6 = A("A", argDouble=23.0)
if (a6.prop != "A#23.0#1") return "fail6: ${a6.prop}"
val a7 = A("A", arg3=2L, argDouble=23.0)
if (a7.prop != "A#23.0#2") return "fail7: ${a7.prop}"
return "OK"
}