Hi, I have a situation I do not understand - here ...
# general-advice
g
Hi, I have a situation I do not understand - here is the simplified code:
Copy code
import kotlinx.coroutines.channels.Channel

class Box<out M>(
    //  ...
)

interface Transport<S> {
  //  ...
}

interface Message {
  // ...
}

fun <T : Message> test(
  consumer: Transport<T>,
  channel: Channel<Box<T>> = Channel()
): Channel<Box<T>> {
  return channel
}

fun main() {
  lateinit var consumer: Transport<out Message> // just to get the right type
  var c = test(consumer)
}
Here the IDE (IntelliJ) does not see any issue. But If I ask IntelliJ to provide the type, I got:
Copy code
var c: Channel<Box<Message>> = test(consumer)
But then IntelliJ itself tells me it's wrong and should be:
Copy code
var c: Channel<out Box<Message>> = test(consumer)
At last, for both type, the can not provide it to the
test
function - IntelliJ tells me it's not the right type
Copy code
val c: Channel<out Box<Message>> = Channel()
test(consumer, c)
Any hint would be greatly appreciated!
c
Shouldn't you use a ReceiveChannel here?