Support suspend conversion in callable reference adaptation
#KT-15917 In Progress
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +SuspendConversion
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun foo1(f: suspend () -> Unit) {}
|
||||
fun bar1() {}
|
||||
|
||||
fun <T> foo2(e: T, f: suspend (T) -> Unit) {}
|
||||
fun bar2(x: Int) {}
|
||||
fun bar2(s: String) {}
|
||||
|
||||
fun test() {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!>(::bar1)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>foo2<!>(42, <!UNRESOLVED_REFERENCE!>::bar2<!>)
|
||||
<!INAPPLICABLE_CANDIDATE!>foo2<!>("str", <!UNRESOLVED_REFERENCE!>::bar2<!>)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>foo2<!>(42, ::bar1)
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +SuspendConversion
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun foo1(f: suspend () -> Unit) {}
|
||||
fun bar1() {}
|
||||
|
||||
fun <T> foo2(e: T, f: suspend (T) -> Unit) {}
|
||||
fun bar2(x: Int) {}
|
||||
fun bar2(s: String) {}
|
||||
|
||||
fun test() {
|
||||
foo1(::bar1)
|
||||
|
||||
foo2(42, ::bar2)
|
||||
foo2("str", ::bar2)
|
||||
|
||||
foo2(42, <!TYPE_MISMATCH!>::bar1<!>)
|
||||
}
|
||||
compiler/testData/diagnostics/tests/suspendConversion/basicSuspendConversionForCallableReference.txt
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
package
|
||||
|
||||
public fun bar1(): kotlin.Unit
|
||||
public fun bar2(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun bar2(/*0*/ s: kotlin.String): kotlin.Unit
|
||||
public fun foo1(/*0*/ f: suspend () -> kotlin.Unit): kotlin.Unit
|
||||
public fun </*0*/ T> foo2(/*0*/ e: T, /*1*/ f: suspend (T) -> kotlin.Unit): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
Vendored
+21
@@ -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() {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!>(::bar1)
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!>(::bar2)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!>(<!UNRESOLVED_REFERENCE!>::bar3<!>) // Should be ambiguity
|
||||
}
|
||||
Vendored
+21
@@ -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
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
public fun bar1(): kotlin.Unit
|
||||
public fun bar2(/*0*/ s: kotlin.String = ...): kotlin.Int
|
||||
public fun bar3(): kotlin.Unit
|
||||
public suspend fun bar3(/*0*/ s: kotlin.String = ...): kotlin.Int
|
||||
public fun foo1(/*0*/ s: SuspendRunnable): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public fun interface SuspendRunnable {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract suspend fun invoke(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// !LANGUAGE: +SuspendConversion
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun unitCoercion(f: suspend () -> Unit) {}
|
||||
fun foo(): Int = 0
|
||||
|
||||
fun defaults(f: suspend (Int) -> String) {}
|
||||
fun bar(i: Int, l: Long = 42L): String = ""
|
||||
|
||||
fun varargs(f: suspend (Int, Int, Int) -> String) {}
|
||||
fun baz(vararg ints: Int): String = ""
|
||||
|
||||
fun unitCoercionAndDefaults(f: suspend () -> Unit) {}
|
||||
fun all(s: String = ""): Int = 0
|
||||
|
||||
fun test() {
|
||||
<!INAPPLICABLE_CANDIDATE!>unitCoercion<!>(::foo)
|
||||
<!INAPPLICABLE_CANDIDATE!>defaults<!>(::bar)
|
||||
<!INAPPLICABLE_CANDIDATE!>varargs<!>(::baz)
|
||||
<!INAPPLICABLE_CANDIDATE!>unitCoercionAndDefaults<!>(::all)
|
||||
}
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// !LANGUAGE: +SuspendConversion
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun unitCoercion(f: suspend () -> Unit) {}
|
||||
fun foo(): Int = 0
|
||||
|
||||
fun defaults(f: suspend (Int) -> String) {}
|
||||
fun bar(i: Int, l: Long = 42L): String = ""
|
||||
|
||||
fun varargs(f: suspend (Int, Int, Int) -> String) {}
|
||||
fun baz(vararg ints: Int): String = ""
|
||||
|
||||
fun unitCoercionAndDefaults(f: suspend () -> Unit) {}
|
||||
fun all(s: String = ""): Int = 0
|
||||
|
||||
fun test() {
|
||||
unitCoercion(::foo)
|
||||
defaults(::bar)
|
||||
varargs(::baz)
|
||||
unitCoercionAndDefaults(::all)
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun all(/*0*/ s: kotlin.String = ...): kotlin.Int
|
||||
public fun bar(/*0*/ i: kotlin.Int, /*1*/ l: kotlin.Long = ...): kotlin.String
|
||||
public fun baz(/*0*/ vararg ints: kotlin.Int /*kotlin.IntArray*/): kotlin.String
|
||||
public fun defaults(/*0*/ f: suspend (kotlin.Int) -> kotlin.String): kotlin.Unit
|
||||
public fun foo(): kotlin.Int
|
||||
public fun test(): kotlin.Unit
|
||||
public fun unitCoercion(/*0*/ f: suspend () -> kotlin.Unit): kotlin.Unit
|
||||
public fun unitCoercionAndDefaults(/*0*/ f: suspend () -> kotlin.Unit): kotlin.Unit
|
||||
public fun varargs(/*0*/ f: suspend (kotlin.Int, kotlin.Int, kotlin.Int) -> kotlin.String): kotlin.Unit
|
||||
Reference in New Issue
Block a user