Brandon Ward

07/24/2019, 8:41 PM
Does anyone know if it is possible to exclude specific functions of a type-safe builder from the
scope verification? See attached example. In case you need a use case to justify my question, my global helper is just something that can supply resources as strings, and it makes sense to be able to do that at various layers of the DSL without needing to repeat the
declaration, but at the same time, other functions not marked as global should have their scope enforced by the compiler so that it helps people use the DSL.


07/24/2019, 8:51 PM
I don't think so, you could specifically repeat the function is every possible scope as a workaround.
😢 1

Casey Brooks

07/24/2019, 9:06 PM
I think you’ll be able to assign
to a variable in the initial
scope, and then refer to that object from child scopes. The
should only limit the implicit scope, but explicit scope (like variabled declared in that scope) should still be accessible
customDsl {
    val globalScope = this
    scopedEntry { /*work*/ }
    nestedObject {
        // this should be allowed because I want it global
        globalScope.globalHelper { /*work*/ }
    globalHelper { /*work*/ }

Brandon Ward

07/24/2019, 9:09 PM
That's not horrible, but still no worse than just needing to call
this@customDsl.globalHelper { /* work */ }
wherever the helper is needed outside the original scope


07/24/2019, 9:56 PM
You can specifically mark the lamdba parameter with
fun scopedEntry(@CustomDslMarker init: Any.() -> Unit)

Brandon Ward

07/24/2019, 9:57 PM
Yeah, I tried that, which allowed my global function to be called globally, but didn't restrict the other scoped functions
I should clarify, it helps a little, some things get properly scoped, but not everything, so I guess it's better than nothing.