Quick question about DSLS (and presumably `DslMark...
# announcements
r
Quick question about DSLS (and presumably
DslMarker
though I still have trouble getting my head around it for some reason). Say I have a part of my DSL like this:
Copy code
class 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): Thing
Is there a way to make it so I cannot access the outer context when an inner context is created?
Copy code
class 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!
            }
        }
    }
}
Basically, I want the
a = "test-4"
line to not even compile as the context has been switched.