mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-17 00:21:28 +00:00
Inner class constructors should use the argument instead of reading outer `this` from a field because if such an access happens before a delegating constructor call, e.g. when evaluating an argument, a JVM bytecode validation error will be thrown. (The only operation on `this` allowed before a delegating constructor call is SETFIELD, and only if the field in question is declared in the same class.)
22 lines
446 B
Kotlin
Vendored
22 lines
446 B
Kotlin
Vendored
interface Callback {
|
|
fun invoke(): String
|
|
}
|
|
|
|
open class Base(val callback: Callback)
|
|
|
|
class Outer {
|
|
val ok = "OK"
|
|
|
|
inner class Inner : Base(
|
|
object : Callback {
|
|
override fun invoke() =
|
|
(object : Callback {
|
|
override fun invoke() = ok
|
|
}).invoke()
|
|
}
|
|
)
|
|
}
|
|
|
|
fun box(): String =
|
|
Outer().Inner().callback.invoke()
|