Found a compiler bug with context-receivers which ...
# getting-started
d
Found a compiler bug with context-receivers which leads to a ClassCastException: 🧵
Copy code
package com.stochastictinkr

class Context(val hello: String = "Hello")
object Receiver {
    val world = "World!"
}

inline fun execute(
    lambda: context(Context) Receiver.() -> Unit,
) {
    Context().also {
        lambda(it, Receiver)
    }
}

fun main() {
    execute { println("$hello $world") }
}
results in:
Copy code
Exception in thread "main" java.lang.ClassCastException: class com.stochastictinkr.Receiver cannot be cast to class com.stochastictinkr.Context (com.stochastictinkr.Receiver and com.stochastictinkr.Context are in unnamed module of loader 'app')
	at com.stochastictinkr.BrokenKt.main(Broken.kt:21)
	at com.stochastictinkr.BrokenKt.main(Broken.kt)
Ah, known issue for years 😞