Is it possible to use the `@DslMarker` annotation ...
# announcements
a
Is it possible to use the
@DslMarker
annotation on a
suspend
scope receiver ? I’m getting an
java.lang.IllegalStateException: Backend Internal error: Exception during IR lowering
exception when I write the following code, but don’t face any issue when I remove the
suspend
modifier :
Copy code
@DslMarker
annotation class MyDslMarker

@MyDslMarker
interface MyDsl

fun something(
    scope: suspend MyDsl.() -> Unit,
) {
}

fun main() {
    something { }
}
y
Do you 100% need it to be suspend? Because if you just want the user to have the ability to call suspend functions then just make your
fun something
inline so that the user can call suspend funs if they're in a suspend scope. Also, try removing the @MyDslMarker while keeping the suspend modifier and check what happens because the issue could be elsewhere
Actually, running this on the Kotlin playground with version 1.4.20 produces the expected results:
Copy code
import kotlinx.coroutines.*

@DslMarker
annotation class MyDslMarker
@MyDslMarker
interface MyDsl
fun something(
    scope: suspend MyDsl.() -> Unit
) {
    runBlocking {
        scope(object : MyDsl {})
    }
}
fun main() {
    something { println("test") }
}
a
Yes, I really need it to be suspending. When I remove the
@MyDslMarker
annotation from
MyDsl
, the snippet compiles and runs without issues. It’s interesting that the code compiles properly on the Kotlin playground; I’m wondering if the issue might come from the fact that I’m using Jetpack Compose (and maybe the new IR backend).
y
Oh yep I figured as much it is probably the new IR backend. There's some bugs here and there that they're polishing. For now I'd say maybe sacrifice the annotation or experiment a bit more with other possible solutions (for example, try a
fun interface
with a suspend function instead)
Apparently fun interfaces can't be suspend; TIL
👍 1
u
It would be awesome if you could report this to the Kotlin issue tracker at https://kotl.in/issue so that we can investigate and fix it properly
a
@udalov I’ve put the code snippet and attached the stacktrace to https://youtrack.jetbrains.com/issue/KT-44623
u
@alexandrepiveteau Thanks! 👍