Higher order function overload ambiguity


#1

Is this supposed to work? The compiler says it should, but it doesn’t:

fun main(args: Array<String>) {
    breaks()
}

fun foo(x: (String) -> String): String = x.invoke("")

fun foo(x: (String) -> Int): Int = x.invoke("")

fun breaks() {
    foo({ s: String -> "" }) // doesn't work 
    foo({ s: String -> "" } as (String) -> String) // works, but says "No cast needed"
    foo({ s: String -> 0 }) // doesn't work
    foo({ s: String -> 0 } as (String) -> Int) // works, but says "No cast needed"
}

Edit: already reported

https://youtrack.jetbrains.com/issue/KT-11265

https://youtrack.jetbrains.com/issue/KT-11293