[Are context-receivers available in Kotlin/Native?...
# kotlin-native
j
[Are context-receivers available in Kotlin/Native?] đź§µ
solved 1
no red 2
I am trying to test out context-receivers in Kotlin/Native • Target: macosArm64 • Kotlin:
1.7.10
I added the feature flag to my
build.gradle.kts
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xcontext-receivers")
    }
}
But when I run the program via
:runDebugExecutable
I get the following error while compiling:
Copy code
The feature "context receivers" is experimental and should be enabled explicitly
s
Not on my machine rn. Replace KotlinCompile with something like KotlinNativeCompile
j
Thanks using
KotlinNativeCompile
class helped get rid of that error.
s
KotlinCompile is only the task for JVM. When the task was named, there was no native
r
I think
AbstractKotlinCompile
gets you all platforms if that’s what you need
j
Could it be that context receivers are currently broken? Created the following simple sample:
Copy code
fun main() {
    with(BasicLogger()) {
        test()
    }
}

context (LoggingContext)
fun test() {
    log("hello world")
}

interface LoggingContext {
    fun log(msg: String)
}

class BasicLogger() : LoggingContext {
    override fun log(msg: String) {
        println(msg)
    }
}
But getting the following compile error:
Copy code
e: java.lang.IllegalStateException: FULL: FUN name:test visibility:public modality:FINAL <> (<this>:de.tm.jonas.LoggingContext) returnType:kotlin.Unit
 Ir: de.tm.jonas#test(de.tm.jonas.LoggingContext){}
 Descriptor: de.tm.jonas#test!de.tm.jonas.LoggingContext(){}

	at org.jetbrains.kotlin.backend.common.serialization.mangle.ManglerChecker$visitDeclaration$2.invoke(ManglerChecker.kt:96)
 ...
s
Context receivers are JVM-only at the moment.
j
Ok so if it is not supported why is the compiler not complaining?