class 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
.
Copy code
@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?
s
Sam
07/27/2022, 7:44 AM
Sounds like you need @DslMarker guess you edited your post to include this already