kotlin-spec icon indicating copy to clipboard operation
kotlin-spec copied to clipboard

Discriminate overload resolution candidates which require (SAM) conversions

Open ice-phoenix opened this issue 4 years ago • 1 comments

Exhibit 1:

package foo

fun interface Callback {
    fun doit(): Unit
}

fun foo(cb: () -> Unit) {} // (1)
fun foo(cb: Callback) {} // (2)

fun test() {
    foo {} // resolved to (1)
}

Exhibit 2:

package foo

fun ambiguous(sfn: suspend () -> Unit) = sfn // (1)
fun ambiguous(fn: () -> Unit) = fn // (2)

fun test(fn: () -> Unit) = ambiguous(fn) // resolved to (2)
// Note: this will need fixing after the compatibility mode disabling

Some additional info available at Quip (Disabling new inference compatibility mode).

ice-phoenix avatar Sep 09 '21 13:09 ice-phoenix

Probably this needs to be postponed for after a more complete SAM conversion design w.r.t. overload resolution is achieved

ice-phoenix avatar Sep 09 '21 13:09 ice-phoenix