Files
kotlin-fork/compiler/testData/diagnostics/tests/suspendConversion/overloadResolutionBySuspendModifier.kt
T
Mikhail Zarechenskiy fb812301b2 Add test to preserve behaviour
It's important to have ambiguity in these cases to introduce overload
 resolution by suspend-modifier without breaking changes in future

 Relates to #KT-23610
2020-06-05 14:07:08 +03:00

19 lines
576 B
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_PARAMETER
fun foo(x: () -> Int) {}
fun foo(x: suspend () -> Int) {}
fun usualCall(): Int = 42
suspend fun suspendCall(): Int = 42
// it's important to have ambiguity in these cases to introduce overload resolution by suspend modifier in future
fun test1() {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!> { usualCall() }
<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!> { <!ILLEGAL_SUSPEND_FUNCTION_CALL!>suspendCall<!>() }
}
// candidate without suspend conversions is more specific
fun test2(f: () -> Int, g: suspend () -> Int) {
foo(f)
foo(g)
}