dave
09/20/2023, 7:47 AMdata object Ctx1
data object Ctx2
interface MyThing<Ctx> {
    context(Ctx)
    fun foo(): String
}
class Ctx1Thing : MyThing<Ctx1> {
    context(Ctx2) override fun foo() = "bob"
}Javier
09/20/2023, 8:10 AMdave
09/20/2023, 8:14 AMJavier
09/20/2023, 8:17 AMnatpryce
09/20/2023, 8:18 AMfun main() {
    val myThing : MyThing<Ctx1> = Ctx1Thing()
    
    with(Ctx2) {
        with(Ctx1) {
            myThing.foo()
        }
    }
}natpryce
09/20/2023, 8:18 AMException in thread "main" java.lang.ClassCastException: class example.signup.Ctx1 cannot be cast to class example.signup.Ctx2 (example.signup.Ctx1 and example.signup.Ctx2 are in unnamed module of loader 'app')
	at example.signup.Ctx1Thing.foo(Example.kt:11)
	at example.signup.ExampleKt.main(Example.kt:20)
	at example.signup.ExampleKt.main(Example.kt)dave
09/20/2023, 8:18 AMinterface MyCtx
data object Ctx1 : MyCtx
data object Ctx2 : MyCtx
interface MyThing<MyCtx> {
    context(MyCtx)
    fun foo(): String
}
class Ctx1Thing : MyThing<Ctx1> {
    context(Ctx2) override fun foo() = "bob"
}dave
09/20/2023, 8:20 AMJavier
09/20/2023, 8:20 AMnatpryce
09/20/2023, 8:24 AMJavier
09/20/2023, 8:26 AMclass Ctx1Thing : MyThing<Ctx1> {
    context(Ctx2) override fun foo() = "bob"
}
This can't work as Ctx1 is not related to Ctx2
The next would fail too
interface MyCtx
data object Ctx1 : MyCtx
data object Ctx2 : MyCtx
interface MyThing<MyCtx> {
    fun foo(param: MyCtx): String
}
class Ctx1Thing : MyThing<Ctx1> {
    override fun foo(param: Ctx1) = "bob" // works
    override fun foo(param: Ctx2) = "bob" // fails
}Javier
09/20/2023, 8:26 AMdave
09/20/2023, 8:26 AMdave
09/20/2023, 8:28 AMdave
09/20/2023, 8:34 AM