Ruckus
11/29/2018, 3:46 AMDslMarkerclass Thing {
    inner class Context<T>(private val gen: () -> T) {
        fun <T> withContext(gen: () -> T, action: Context<T>.() -> Unit) = Context(gen).action()
        operator fun String.invoke(action: T.() -> Unit) {
            val s = gen()
            // Setup s
            s.action()
            // Cleanup s
        }
    }
}
fun <T> thing(gen: () -> T, action: Thing.Context<T>.() -> Unit): Thingclass A {
    var a: String = ""
}
class B {
    var b: String = ""
}
...
thing(::A) {
    "test-1" {
        a = "test-1"
        "test-2 {
            a = "test-2"  // Still works as we're still in Context<A>
            withContext(::B) {  // Switch context
                b = "test-3"  // Works
                a = "test-4"  // <-- Should not compile!
            }
        }
    }
}a = "test-4"