Given the following: ``` fun <I, O> Collecti...
# announcements
j
Given the following:
Copy code
fun <I, O> Collection<I>.flatMap(func: (I) -> List<O>): List<O> = TODO()
fun <I, O> Collection<I>.flatMap(func: (I) -> Collection<O>): Collection<O> = TODO()
fun <I, O> List<I>.flatMap(func: (I) -> Collection<O>): Collection<O> = TODO()

fun main(vararg args: String) {
  val collection: Collection<Int> = listOf(1)
  listOf(1).flatMap { collection }
}
This currently fails with:
Copy code
Error:(7, 12) Cannot choose among the following candidates without completing type inference: 
public fun <I, O> Collection<Int>.flatMap(func: (Int) -> Collection<???>): Collection<???> defined in root package
public fun <I, O> Collection<Int>.flatMap(func: (Int) -> List<???>): List<???> defined in root package
public fun <I, O> List<Int>.flatMap(func: (Int) -> Collection<???>): Collection<???> defined in root package
If I specify
flatMap<Int, Int>
explicitly, I then get:
Copy code
Error:(7, 12) Overload resolution ambiguity: 
public fun <I, O> Collection<Int>.flatMap(func: (Int) -> Collection<Int>): Collection<Int> defined in root package
public fun <I, O> Collection<Int>.flatMap(func: (Int) -> List<Int>): List<Int> defined in root package
public fun <I, O> List<Int>.flatMap(func: (Int) -> Collection<Int>): Collection<Int> defined in root package
Is this expected? I would think that given the type information, the third function would match. But even without explicit type information, I would expect it to match. The receiver type is the most specific and then function signature matches perfectly.