class Box(var item: String?) fun expectString(it: String) {} fun Box.test() { val other = Box("") myRun { if (item != null) { expectString(item) other.item = null expectString(item) this.item = null expectString(item) } } var item: String? = "OK" myRun { if (item != null) { this.item = null expectString(item) } } } fun myRun(block: () -> Unit) {}