I want to use context parameters to scope an exist...
# getting-started
h
I want to use context parameters to scope an existing Kotlin DSL. According to the KEEP, this should be supported, but I failed to create the functions.
As a user, I want to write this code:
Copy code
fun TestBuilder.scoped() {
    scopedCase {
        case {
            scoped {
                action()
            }
        }
    }
}
And I use this existing dsl:
Copy code
@DslMarker
annotation class TestDsl

@TestDsl
interface TestBuilder {
    fun case(action: CaseBuilder.() -> Unit)
}

@TestDsl
interface CaseBuilder {
    fun then(action: Then.() -> Unit)
}

@TestDsl
interface Then {
    fun action()
}
I tried this code:
Copy code
fun TestBuilder.scopedCase(
    action: context(String) TestBuilder.() -> Unit
) {
    
}

context(_: String)
fun CaseBuilder.scoped(thenAction: Then.() -> Unit) {
    then {
        thenAction()
    }
}
But I always get this error that I want to prevent:
scopedCase and scoped cannot be called in this context with an implicit receiver
Turns out, it does work as expected when I remove the DslMarker annotation 🤔
y
I think it might be the case that extension receivers are prioritized over contexts. You might wanna check if that's happening here or not. If that's not the case, then this is absolutely a bug with DslMarker
h
Thanks, afaik §7.7 mentions scoped DslMarker so I filled an issue: https://youtrack.jetbrains.com/issue/KT-77510