Jason5lee
07/27/2022, 7:43 AMclass Scope {
fun method(block: () -> Unit) {}
}
fun scope(block: Scope.() -> Unit) {}
fun main() {
scope {
method {
method { } // I want to disallow using the scope inside the method
}
}
}
I want to disallow calling method on the Scope
inside the method
.
I know I can have a dummy receive object and mark the Scope
and the dummy object DslMarker
.
@DslMarker
annotation class MyDslMarker
@MyDslMarker
class Scope {
fun method(block: Context.() -> Unit) {}
}
@MyDslMarker
object Context // Dummy object
fun scope(block: Scope.() -> Unit) {}
fun main() {
scope {
method {
method { } // Compiler error now
}
}
}
Any better solution?Sam
07/27/2022, 7:44 AMJason5lee
07/27/2022, 7:47 AMSam
07/27/2022, 7:48 AM