jw
08/06/2017, 6:10 PMfun <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:
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:
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.