Add 'suspendWithCurrentContinuation' and 'Suspend' object in built-ins
They are part of the new suspension convention, relevant support in backends will be added in later commits #KT-14924 In Progress
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
class Controller {
|
||||
suspend fun noParams(): Unit = suspendWithCurrentContinuation {
|
||||
if (hashCode() % 2 == 0) {
|
||||
it.resume(Unit)
|
||||
Suspend
|
||||
}
|
||||
else {
|
||||
Unit
|
||||
}
|
||||
}
|
||||
suspend fun yieldString(value: String) = suspendWithCurrentContinuation<Int> {
|
||||
it.resume(1)
|
||||
it checkType { _<Continuation<Int>>() }
|
||||
it.resume(<!TYPE_MISMATCH!>""<!>)
|
||||
|
||||
// We can return anything here, 'suspendWithCurrentContinuation' is not very type-safe
|
||||
// Also we can call resume and then return the value too, but it's still just our problem
|
||||
"Not-int"
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {}
|
||||
|
||||
fun test() {
|
||||
builder {
|
||||
noParams() checkType { _<Unit>() }
|
||||
yieldString("abc") checkType { _<Int>() }
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
public fun builder(/*0*/ coroutine c: Controller.() -> kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class Controller {
|
||||
public constructor Controller()
|
||||
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 final suspend fun noParams(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
public final suspend fun yieldString(/*0*/ value: kotlin.String): kotlin.Int
|
||||
}
|
||||
Reference in New Issue
Block a user