var result = "" interface A { fun foo() { result += "foo;" } } interface B : A { fun hoo() { result += "hoo;" } } fun doer(init: () -> T): T = init() class Z { operator fun invoke(init: Z.() -> T): T = init() infix fun doer(init: Z.() -> T): T = init() } interface ARoot { val self : T infix fun consume(init: T.() -> U): U = self.init() operator fun invoke(init: T.() -> U): U = self.init() } class Y : ARoot { override val self: Y get() = this } fun box(): String { doer { object : B {} }.hoo() val z = Z() val y = Y() z.doer { object : B {} }.hoo() y { z { object : B {} } }.hoo() y.consume { z { object : B {} } }.hoo() z { object : B {} }.foo() z.doer { object : B {} }.foo() z.doer { object : B {} }.hoo() return if (result == "hoo;hoo;hoo;hoo;foo;foo;hoo;") "OK" else "Fail: $result" }