Javier
07/30/2023, 1:46 PMList<Int>
as it is inferring, I guess, the last context receiver.
I even get a compile error if I try to assign them to variables as you can see in the images, so I guess it is not currently possible, right?
context(List<String>, List<Int>)
fun foo() = this@List
I really miss a #context-receivers channel, not only to ask about how to use them and possible design changes to how we develop programs without them versus them, but to report missing features and/or bugsWout Werkman
07/30/2023, 2:25 PMtypealias StringList = List<String>
context(StringList, List<Int>)
fun foo() = this@StringList
I really miss a #context-receivers channelI agree that there is not a good source to find how to use context receivers idiomatically. I'd say that posting here is a good start for sharing your thoughts. If you want to influence the evolution of the language, your best chance is at all times to share good use cases to support your proposal/concern.
Javier
07/30/2023, 2:43 PMthis@List<String>
should be allowed
https://youtrack.jetbrains.com/issue/KT-60810/FIR-Context-receivers-with-type-parameters-doesnt-workJavier
07/30/2023, 2:43 PMYoussef Shoaib [MOD]
07/30/2023, 7:35 PMcontext(A) fun <A> given(): A = this@A
context(List<String>, List<Int>) fun test() {
val strs = given<List<String>>()
val ints = given<List<Int>>()
}
And it resolves perfectlyYoussef Shoaib [MOD]
07/30/2023, 7:40 PMfun main() = with(listOf("hello")) {
with(listOf(42)){
test()
}
}
context(A) fun <A> given(): A = this@A
context(List<String>, List<Int>) fun test() {
val strs = given<List<String>>()
val ints = given<List<Int>>()
println(strs)
println(ints)
}
given
or a function like it should 100% exist in the stdlib. It's a must have in the context receiver world, especially when you're inside a contextual lambda where currently this@ doesn't work. given
is just IMO the better solution, and it needs no language support reallyJavier
07/30/2023, 7:54 PMYoussef Shoaib [MOD]
07/30/2023, 7:55 PM