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:
@@ -0,0 +1,16 @@
|
||||
package-fragment kotlin.coroutines
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") public inline suspend fun </*0*/ T> suspendWithCurrentContinuation(/*0*/ body: (kotlin.coroutines.Continuation<T>) -> kotlin.Any?): T
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS}) @kotlin.annotation.Retention(value = AnnotationRetention.BINARY) public final annotation class AllowSuspendExtensions : kotlin.Annotation {
|
||||
/*primary*/ public constructor AllowSuspendExtensions()
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") public interface Continuation</*0*/ in P> {
|
||||
public abstract fun resume(/*0*/ data: P): kotlin.Unit
|
||||
public abstract fun resumeWithException(/*0*/ exception: kotlin.Throwable): kotlin.Unit
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") public object Suspend {
|
||||
/*primary*/ private constructor Suspend()
|
||||
}
|
||||
+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
|
||||
}
|
||||
@@ -4300,6 +4300,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("suspendWithCurrentContinuation.kt")
|
||||
public void testSuspendWithCurrentContinuation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendWithCurrentContinuation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("tryCatchLambda.kt")
|
||||
public void testTryCatchLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/tryCatchLambda.kt");
|
||||
|
||||
@@ -91,7 +91,7 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
ModuleDescriptor module =
|
||||
LazyResolveTestUtilsKt.createResolveSessionForFiles(getEnvironment().getProject(), files, false).getModuleDescriptor();
|
||||
|
||||
for (FqName packageFqName : CollectionsKt.listOf(BUILT_INS_PACKAGE_FQ_NAME, COLLECTIONS_PACKAGE_FQ_NAME, RANGES_PACKAGE_FQ_NAME)) {
|
||||
for (FqName packageFqName : CollectionsKt.listOf(BUILT_INS_PACKAGE_FQ_NAME, COLLECTIONS_PACKAGE_FQ_NAME, RANGES_PACKAGE_FQ_NAME, COROUTINES_PACKAGE_FQ_NAME)) {
|
||||
PackageFragmentDescriptor fromLazyResolve =
|
||||
CollectionsKt.single(module.getPackage(packageFqName).getFragments());
|
||||
if (fromLazyResolve instanceof LazyPackageDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user