Not sure if it has its place here, but it seems to...
# eap
j
Not sure if it has its place here, but it seems to be a bug with 1.7.20-Beta, so I'm writing here. Trying to play with context receivers, I am defining the following function:
Copy code
fun <C1, C2, R> withBoth(c1: C1, c2: C2, block: context(C1, C2) () -> R): R = block(c1, c2)
And I get this compiler error:
Copy code
Subtyping relation between context receivers is prohibited
Is this a bug, or did I mess up the syntax somewhere? There is no subtyping intended anywhere here. Note that moving
C2
as a regular receiver fixes the compilation:
Copy code
fun <C1, C2, R> withBoth(c1: C1, c2: C2, block: context(C1) C2.() -> R): R = block(c1, c2)
Some more context: I'm replying to this stackoverflow question. And I found what seemed like a bug when trying to call
withBoth
(defined with 2 context receivers) with a lambda (in 1.7.10). It works fine when passing a method reference as the
block
. Since it is pretty similar to https://youtrack.jetbrains.com/issue/KT-51243, and that one is supposedly fixed in 1.7.20, I wanted to try my luck with 1.7.20-Beta to see if it worked fine.
y
You can suppress that error btw. The subtyping relationship error is so broken that I automatically just suppress it in every file where I define context functions lol
b
@Youssef Shoaib [MOD] How can you suppress it? I can't find the correct string for it
y
@Suppress("SUBTYPING_BETWEEN_CONTEXT_RECEIVERS")
b
Thank you 🙂