I’m not sure if I hit a compiler limitation or a b...
# compiler
c
I’m not sure if I hit a compiler limitation or a bug regarding context receivers. In the following example, the value
program
, which is a contextual function can not be evaluated when the context parameter is brought into scope. Should I file a bug report? 🤔
Copy code
fun interface Context1 {
    fun c1(): Int
}

fun interface Context2 {
    fun c2(v: Int): String
}


context(Context1)
fun useC1(): context(Context2) (Int) -> String {
    val x = c1()
    return { c2(it + x) }
}

fun main(args: Array<String>) {
    val program: context(Context2) (Int) -> String = with(Context1 { 42 }) {
        useC1()
    }

    //this works
    val result = program(Context2 { "the value is $it" }, 2)
   
    //but this doesn't work
    with(Context2 { "the value is $it" }) {
        program(2)
    }
}
d
Looks like a bug for me Please report an issue
c
Will do. Thank you
👍 1
y
@dmitriy.novozhilov Isn't this just the current lambda calling limitation? as in, to invoke a contextual lambda currently you need to provide it with all its arguments as parameters? AFAIK this is a deliberate limitation?
d
Hm, indeed I forgot about that limitation