mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Call object's constructor in <clinit> and ignore the result, but in the first line of <init> save the current "this" to INSTANCE$ #KT-4516 Fixed #KT-4543 Fixed #KT-5291 Fixed #KT-5523 Fixed #KT-5582 Fixed
25 lines
473 B
Kotlin
Vendored
25 lines
473 B
Kotlin
Vendored
public inline fun <T> T.with(f: T.() -> Unit): T {
|
|
this.f()
|
|
return this
|
|
}
|
|
|
|
public class Cls {
|
|
val string = "Cls"
|
|
val buffer = StringBuilder().with {
|
|
append(string)
|
|
}
|
|
}
|
|
|
|
public object Obj {
|
|
val string = "Obj"
|
|
val buffer = StringBuilder().with {
|
|
append(string)
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
if (Cls().buffer.toString() != "Cls") return "Fail class"
|
|
if (Obj.buffer.toString() != "Obj") return "Fail object"
|
|
return "OK"
|
|
}
|