Prohibit using suspend functions as SAM in fun interfaces

#KT-40978 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-08-10 18:49:55 +03:00
parent 607f99ed3c
commit e49cdf0ca2
12 changed files with 60 additions and 10 deletions
@@ -71,7 +71,7 @@ interface BaseWithGeneric {
fun interface GoodExtensionGeneric : GoodGeneric<String>
fun interface GoodSuspend {
suspend fun invoke()
<!FUN_INTERFACE_WITH_SUSPEND_FUNCTION!>suspend<!> fun invoke()
}
class WithNestedFun<K> {
@@ -0,0 +1,14 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument +FunctionalInterfaceConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -NOTHING_TO_INLINE
fun interface SuspendRunnable {
suspend fun invoke()
}
fun run(r: SuspendRunnable) {}
suspend fun bar() {}
fun test() {
run(::bar)
}
@@ -1,9 +1,8 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument +FunctionalInterfaceConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -NOTHING_TO_INLINE
fun interface SuspendRunnable {
suspend fun invoke()
<!FUN_INTERFACE_WITH_SUSPEND_FUNCTION!>suspend<!> fun invoke()
}
fun run(r: SuspendRunnable) {}
@@ -2,7 +2,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun interface SuspendRunnable {
suspend fun invoke()
<!FUN_INTERFACE_WITH_SUSPEND_FUNCTION!>suspend<!> fun invoke()
}
fun foo(s: SuspendRunnable) {}
@@ -2,7 +2,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun interface SuspendRunnable {
suspend fun run()
<!FUN_INTERFACE_WITH_SUSPEND_FUNCTION!>suspend<!> fun run()
}
object Test1 {
@@ -0,0 +1,21 @@
// !LANGUAGE: +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun interface SuspendRunnable {
suspend fun invoke()
}
fun foo1(s: SuspendRunnable) {}
fun bar1() {}
fun bar2(s: String = ""): Int = 0
fun bar3() {}
suspend fun bar3(s: String = ""): Int = 0
fun test() {
foo1(::bar1)
foo1(::bar2)
foo1(::bar3) // Should be ambiguity
}
@@ -1,9 +1,8 @@
// FIR_IDENTICAL
// !LANGUAGE: +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun interface SuspendRunnable {
suspend fun invoke()
<!FUN_INTERFACE_WITH_SUSPEND_FUNCTION!>suspend<!> fun invoke()
}
fun foo1(s: SuspendRunnable) {}
@@ -2,7 +2,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun interface SuspendRunnable {
suspend fun run()
<!FUN_INTERFACE_WITH_SUSPEND_FUNCTION!>suspend<!> fun run()
}
fun foo(r: SuspendRunnable) {}