Files
kotlin/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/inlineOnly.kt
Alexander Udalov ec2dd58165 Remove LANGUAGE_VERSION from codegen tests on coroutines
Use `// !LANGUAGE: -ReleaseCoroutines` instead in tests which require
old (1.2) coroutines, and nothing in tests which require new coroutines
because master is already 1.3. Also remove superfluous API_VERSION and
other directives which have no effect anymore. Do not include runtime
automatically with `WITH_COROUTINES`/`COMMON_COROUTINES_TEST` in box
tests; require `WITH_RUNTIME` for that (majority of tests already had it
anyway), but remove it from bytecode text tests where runtime is always
added automatically. Fix the coroutine package selection code in
KotlinTestUtils and update the bunch files correspondingly.

Disable tests in `box/coroutines/noStdLib` on JVM: despite the name,
these tests were launched with stdlib because of the code in
CodegenTestCase, and they do not work without it because at least
CoroutineUtil.kt requires stdlib to compile correctly
2018-12-20 12:53:23 +01:00

71 lines
1.5 KiB
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// NO_CHECK_LAMBDA_INLINING
// FILE: inlined.kt
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
var result = "FAIL"
var i = 0
var finished = false
var proceed: () -> Unit = {}
suspend fun suspendHere() = suspendCoroutine<Unit> {
i++
proceed = { it.resume(Unit) }
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
inline suspend fun inlineMe() {
suspendHere()
suspendHere()
suspendHere()
suspendHere()
suspendHere()
}
// FILE: inlineSite.kt
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun builder(c: suspend () -> Unit) {
val continuation = object: Continuation<Unit> {
override val context: CoroutineContext
get() = EmptyCoroutineContext
override fun resumeWith(r: Result<Unit>) {
r.getOrThrow()
proceed = {
result = "OK"
finished = true
}
}
}
c.startCoroutine(continuation)
}
suspend fun inlineSite() {
inlineMe()
inlineMe()
}
fun box(): String {
builder {
inlineSite()
}
for (counter in 0 until 10) {
if (i != counter + 1) return "Expected ${counter + 1}, got $i"
proceed()
}
if (i != 10) return "FAIL $i"
if (finished) return "resume on root continuation is called"
proceed()
if (!finished) return "resume on root continuation is not called"
return result
}