4365084645
Consider a context with uninitialized this, e.g.:
fun foo() {
val x = "..."
class Local(y: String) : Base(L@{ x + y })
}
Lambda 'L' is an argument of a super class constructor call.
Here 'this@Local' is not initialized yet. Thus local variables captured
in 'Local' can't be used. Instead, they should be captured by lambda 'L'
itself.
Note that lambda 'L' sees both 'x' and 'y' as local variables that
should be captured.
When in context with uninitialized this (generating arguments for super
type constructor or delegating constructor call), and a variable in
question is not found in the current context, use enclosing local lookup
to determine whether a local variable should be captured by a closure.
11 lines
177 B
Kotlin
Vendored
11 lines
177 B
Kotlin
Vendored
open class Base(val fn: () -> String)
|
|
|
|
fun box(): String {
|
|
val ok = "OK"
|
|
|
|
class Local {
|
|
inner class Inner : Base({ ok })
|
|
}
|
|
|
|
return Local().Inner().fn()
|
|
} |