Kotlin / kotlin-spec

Kotlin Language Specification:
https://kotlinlang.org/spec
Apache License 2.0
393 stars 81 forks source link

Discriminate overload resolution candidates which require (SAM) conversions #95

Open ice-phoenix opened 3 years ago

ice-phoenix commented 3 years ago

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 commented 3 years ago

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