Prevent accidental access to an outer receiver
Nested receiver lambdas can make outer builder functions callable from an inner block. A DSL marker restricts implicit receiver resolution among marked receivers and catches accidental nesting mistakes at compile time.
@DslMarker
annotation class StudyDsl
@StudyDsl
class CourseBuilder {
fun section(block: SectionBuilder.() -> Unit) { SectionBuilder().block() }
}
@StudyDsl
class SectionBuilder {
fun lesson(title: String) { require(title.isNotBlank()) }
}
Inside a section block, an unqualified call to the outer course's section operation is restricted. Explicitly qualified access may still be possible; a DSL marker is a clarity mechanism, not a security boundary or complete validation system.
Exercise
Add nested calls demonstrating the accidental outer access, first without the marker and then with it. Keep a small compile-failure example separate from normal runnable examples.
Check: explain why the marker cannot enforce runtime rules such as unique names or a minimum lesson count. Those still belong in builder validation.