Files
kotlin-fork/compiler/testData/codegen/box/closures/subclosuresWithinInitializers.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

25 lines
647 B
Kotlin
Vendored

fun <R> run(block: () -> R) = block()
inline fun <R> inlineRun(block: () -> R) = block()
class Outer(val outerProp: String) {
fun foo(arg: String): String {
class Local {
val work1 = run { outerProp + arg }
val work2 = inlineRun { outerProp + arg }
val obj = object : Any() {
override fun toString() = outerProp + arg
}
override fun toString() = "${work1}#${work2}#${obj.toString()}"
}
return Local().toString()
}
}
fun box(): String {
val res = Outer("O").foo("K")
if (res != "OK#OK#OK") return "fail: $res"
return "OK"
}