Does anyone know if it is possible to exclude spec...
# announcements
b
Does anyone know if it is possible to exclude specific functions of a type-safe builder from the
@DslMarker
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
globalHelper
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.
k
I don't think so, you could specifically repeat the function is every possible scope as a workaround.
😢 1
c
I think you’ll be able to assign
this
to a variable in the initial
customDsl
scope, and then refer to that object from child scopes. The
DslMarkers
should only limit the implicit scope, but explicit scope (like variabled declared in that scope) should still be accessible
Copy code
customDsl {
    val globalScope = this
    
    scopedEntry { /*work*/ }
    nestedObject {
        // this should be allowed because I want it global
        globalScope.globalHelper { /*work*/ }
    }
    globalHelper { /*work*/ }
}
b
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
d
You can specifically mark the lamdba parameter with
@CustomDslMarker
.
fun scopedEntry(@CustomDslMarker init: Any.() -> Unit)
b
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.