Support common calls on suspend function typed values

Also support multiple value parameters in suspend function type

 #KT-15379 Fixed
 #KT-15380 Fixed
This commit is contained in:
Denis Zharkov
2016-12-21 14:15:46 +03:00
parent d0ba048342
commit 8475869fb3
29 changed files with 299 additions and 77 deletions
@@ -0,0 +1,31 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS
import kotlin.coroutines.*
suspend fun suspendHere(v: String): String = CoroutineIntrinsics.suspendCoroutineOrReturn { x ->
x.resume(v)
CoroutineIntrinsics.SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun foo(c: suspend Double.(Long, Int, String) -> String) = (1.0).c(56L, 55, "abc")
fun box(): String {
var result = ""
var final = ""
builder {
final = foo { l, i, s ->
result = suspendHere("$this#$l#$i#$s")
"OK"
}
}
if (result != "1.0#56#55#abc") return "fail: $result"
return final
}
@@ -0,0 +1,37 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS
import kotlin.coroutines.*
suspend fun suspendHere(v: String): String = CoroutineIntrinsics.suspendCoroutineOrReturn { x ->
x.resume(v)
CoroutineIntrinsics.SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun foo1(c: suspend () -> Unit) = c()
suspend fun foo2(c: suspend String.() -> Int) = "2".c()
suspend fun foo3(c: suspend (String) -> Int) = c("3")
fun box(): String {
var result = ""
builder {
foo1 {
result = suspendHere("begin#")
}
val q2 = foo2 { result += suspendHere(this) + "#"; 1 }
val q3 = foo3 { result += suspendHere(it); 2 }
if (q2 != 1) throw RuntimeException("fail q2")
if (q3 != 2) throw RuntimeException("fail q3")
}
if (result != "begin#2#3") return "fail: $result"
return "OK"
}
@@ -0,0 +1,20 @@
public final class CoroutineUtilKt {
public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
}
public final class EmptyContinuation {
public final static field INSTANCE: EmptyContinuation
private method <init>(): void
public method resume(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void
public method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
}
public final class ManyParametersKt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
public final static @org.jetbrains.annotations.Nullable method foo(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function5, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method suspendHere(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
}
@@ -0,0 +1,22 @@
public final class CoroutineUtilKt {
public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
}
public final class EmptyContinuation {
public final static field INSTANCE: EmptyContinuation
private method <init>(): void
public method resume(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void
public method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
}
public final class SimpleKt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
public final static @org.jetbrains.annotations.Nullable method foo1(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method foo2(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method foo3(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method suspendHere(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
}
@@ -4,7 +4,7 @@ class GenericController<T> {
suspend fun yield(t: T) {}
}
fun <S, P1, P2, R> generate(p1: P1, p2: List<P2>, g: suspend <!UNSUPPORTED!>GenericController<S>.(P1, P2) -> R<!>): Four<S, P1, P2, R> = TODO()
fun <S, P1, P2, R> generate(p1: P1, p2: List<P2>, g: suspend GenericController<S>.(P1, P2) -> R): Four<S, P1, P2, R> = TODO()
val test1 = generate(1, listOf("")) { p1, p2 ->
yield(p1)
@@ -13,4 +13,4 @@ val test1 = generate(1, listOf("")) { p1, p2 ->
}
fun <X> listOf(vararg x: X): List<X> = TODO()
class Four<X, Y, Z, T>
class Four<X, Y, Z, T>
@@ -4,7 +4,7 @@ class GenericController<T> {
suspend fun yield(t: T) {}
}
fun <S> generate(g: suspend <!UNSUPPORTED!>GenericController<S>.(S) -> Unit<!>): S = TODO()
fun <S> generate(g: suspend GenericController<S>.(S) -> Unit): S = TODO()
val test1 = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>generate<!> {
yield(4)
@@ -12,7 +12,7 @@ fun <T> manyArgumentsBuilder(
c3: suspend () -> Int
):T = null!!
fun severalParamsInLambda(c: suspend <!UNSUPPORTED!>(String, Int) -> Unit<!>) {}
fun severalParamsInLambda(c: suspend (String, Int) -> Unit) {}
fun foo() {
builder({ 1 })
@@ -1,7 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun <T> withS(x: T, sfn: suspend <!UNSUPPORTED!>(T) -> Unit<!>) = x
fun <T> withS(x: T, sfn: suspend (T) -> Unit) = x
val test1 = withS(100) {}
fun <TT> test2(x: TT) = withS(x) {}
fun <TT> test2(x: TT) = withS(x) {}
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun <T1, T2> withS2(x: T1, sfn1: suspend <!UNSUPPORTED!>(T1) -> T2<!>, sfn2: suspend <!UNSUPPORTED!>(T2) -> Unit<!>): T2 = null!!
fun <T1, T2> withS2(x: T1, sfn1: suspend (T1) -> T2, sfn2: suspend (T2) -> Unit): T2 = null!!
val test1 = withS2(100, { it.toLong().toString() }, { it.length })
val test1 = withS2(100, { it.toLong().toString() }, { it.length })
@@ -0,0 +1,10 @@
suspend fun foo1(q: suspend () -> Unit) = q()
suspend fun foo2(x: suspend (Int) -> String) = x(1)
suspend fun foo3(y: suspend String.(Int) -> Double) = "".y(1)
suspend fun String.foo4(y: suspend String.(Int) -> Double) = "".y(1)
fun noSuspend(x: suspend (Int) -> String) {
<!ILLEGAL_SUSPEND_FUNCTION_CALL!>x<!>(1)
}
@@ -0,0 +1,7 @@
package
public suspend fun foo1(/*0*/ q: suspend () -> kotlin.Unit): kotlin.Unit
public suspend fun foo2(/*0*/ x: suspend (kotlin.Int) -> kotlin.String): kotlin.String
public suspend fun foo3(/*0*/ y: suspend kotlin.String.(kotlin.Int) -> kotlin.Double): kotlin.Double
public fun noSuspend(/*0*/ x: suspend (kotlin.Int) -> kotlin.String): kotlin.Unit
public suspend fun kotlin.String.foo4(/*0*/ y: suspend kotlin.String.(kotlin.Int) -> kotlin.Double): kotlin.Double
@@ -2,5 +2,5 @@ typealias SuspendFn = suspend () -> Unit
val test1: suspend () -> Unit = {}
val test2: suspend Any.() -> Unit = {}
val test3: suspend <!UNSUPPORTED!>Any.(Int) -> Int<!> = { k: Int -> k + 1 }
val test4: SuspendFn = {}
val test3: suspend Any.(Int) -> Int = { k: Int -> k + 1 }
val test4: SuspendFn = {}
@@ -12,7 +12,7 @@ typealias Test5 = List<suspend () -> Unit>
typealias Test6 = <!WRONG_MODIFIER_TARGET!>suspend<!> List<() -> Unit>
typealias Test7 = <!WRONG_MODIFIER_TARGET!>suspend<!> SAM
typealias Test8 = <!WRONG_MODIFIER_TARGET!>suspend<!> <!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
typealias Test9 = suspend <!UNSUPPORTED!>(() -> Unit) -> Unit<!>
typealias Test10 = suspend <!UNSUPPORTED!>(suspend () -> Unit) -> Unit<!>
typealias Test9 = suspend (() -> Unit) -> Unit
typealias Test10 = suspend (suspend () -> Unit) -> Unit
typealias Test11 = suspend () -> (suspend () -> Unit)
typealias Test12 = suspend <!UNSUPPORTED!>(suspend (() -> Unit)) -> Unit<!>
typealias Test12 = suspend (suspend (() -> Unit)) -> Unit
@@ -1,2 +1,2 @@
fun test1(sfn: suspend () -> Unit) = <!FUNCTION_EXPECTED!>sfn<!>()
fun test2(sfn: suspend () -> Unit) = sfn.<!UNRESOLVED_REFERENCE!>invoke<!>()
fun test1(sfn: suspend () -> Unit) = <!ILLEGAL_SUSPEND_FUNCTION_CALL!>sfn<!>()
fun test2(sfn: suspend () -> Unit) = sfn.<!ILLEGAL_SUSPEND_FUNCTION_CALL!>invoke<!>()
@@ -1,4 +1,4 @@
package
public fun test1(/*0*/ sfn: suspend () -> kotlin.Unit): [ERROR : Error function type]
public fun test2(/*0*/ sfn: suspend () -> kotlin.Unit): [ERROR : Error function type]
public fun test1(/*0*/ sfn: suspend () -> kotlin.Unit): kotlin.Unit
public fun test2(/*0*/ sfn: suspend () -> kotlin.Unit): kotlin.Unit
@@ -1,4 +1,4 @@
typealias Test1 = suspend <!UNSUPPORTED!>(Int) -> Unit<!>
typealias Test2 = suspend <!UNSUPPORTED!>Int.(Int) -> Unit<!>
typealias Test3 = List<suspend <!UNSUPPORTED!>(Int) -> Unit<!>>
typealias Test4 = List<suspend <!UNSUPPORTED!>Int.(Int) -> Unit<!>>
typealias Test1 = suspend (Int) -> Unit
typealias Test2 = suspend Int.(Int) -> Unit
typealias Test3 = List<suspend (Int) -> Unit>
typealias Test4 = List<suspend Int.(Int) -> Unit>