Skip to content

Commit

Permalink
Minor. Make test actually suspend and add a test without suspension
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmirus committed Apr 23, 2021
1 parent 23ffbe4 commit f7a9bc3
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 7 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// FILE: a.kt
@file:JvmMultifileClass
@file:JvmName("A")

import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*

@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)

suspend fun <T> suspendHere(t: T): T = t

suspend fun f(): I = I(suspendHere("OK"))

// FILE: z.kt
import helpers.*
import kotlin.coroutines.*

fun box(): String {
var result = "fail"
suspend { result = f().x as String }.startCoroutine(EmptyContinuation)
return result
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS_IR

import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*

@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)

class C {
private suspend fun f(): I {
return I("OK")
}

fun g() = suspend { f() }
}

val c: Continuation<Unit>? = null

fun box(): String {
var result = "fail"
suspend { result = C().g()().x as String }.startCoroutine(EmptyContinuation)

return result
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TARGET_PLATFORM: JVM
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// FILE: a.kt
Expand All @@ -11,12 +11,14 @@ import kotlin.coroutines.intrinsics.*
@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)

suspend fun <T> suspendHere(x: T): T = suspendCoroutineUninterceptedOrReturn {
it.resume(x)
suspend fun <T> suspendHere(): T = suspendCoroutineUninterceptedOrReturn {
c = it as Continuation<Any?>
COROUTINE_SUSPENDED
}

suspend fun f(): I = I(suspendHere("OK"))
var c: Continuation<Any?>? = null

suspend fun f(): I = I(suspendHere<String>())

// FILE: z.kt
import helpers.*
Expand All @@ -25,5 +27,6 @@ import kotlin.coroutines.*
fun box(): String {
var result = "fail"
suspend { result = f().x as String }.startCoroutine(EmptyContinuation)
c?.resume("OK")
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ import kotlin.coroutines.intrinsics.*
@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)

suspend fun <T> suspendHere(x: T): T = suspendCoroutineUninterceptedOrReturn {
it.resume(x)
suspend fun <T> suspendHere(): T = suspendCoroutineUninterceptedOrReturn {
c = it as Continuation<Any?>
COROUTINE_SUSPENDED
}

var c: Continuation<Any?>? = null

class C {
private suspend fun f(): I = I(suspendHere("OK"))
private suspend fun f(): I = I(suspendHere<String>())

fun g() = suspend { f() }
}

fun box(): String {
var result = "fail"
suspend { result = C().g()().x as String }.startCoroutine(EmptyContinuation)

c?.resume("OK")
return result
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f7a9bc3

Please sign in to comment.