Files
kotlin-fork/compiler/testData/codegen/boxInline/suspend/multipleLocals.kt
T
Ilmir Usmanov f60787d57c Move coroutines to kotlin.coroutines package: tests
Introduce COMMON_COROUTINES_TEST directive.
Every test with this directive is run twice: one time with
language version 1.2 and kotlin.coroutines.experimental package
and the other time with language version 1.3 and kotlin.coroutines
package. Each run is a separate method: with suffixes _1_2 and _1_3
respectively.
However, since codegen of release coroutines is not supported in JS
backend, we generate only one method: with suffix _1_2.
 #KT-23362
2018-04-23 21:51:59 +03:00

125 lines
2.3 KiB
Kotlin
Vendored

// FILE: inlined.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
object Result {
var a: String = ""
var b: Int = 0
}
suspend inline fun inlineMe(c: suspend () -> Unit) {
var a = ""
var b = 0
val r = object: Runnable {
override fun run() {
b++
a += "a"
}
}
r.run()
c()
r.run()
Result.a = a
Result.b = b
}
suspend inline fun noinlineMe(noinline c: suspend () -> Unit) {
var a = ""
var b = 0
val r = object: Runnable {
override fun run() {
b += 2
a += "b"
}
}
r.run()
c()
r.run()
Result.a += a
Result.b += b
}
suspend inline fun crossinlineMe(crossinline c: suspend () -> Unit) {
var a = ""
var b = 0
val r = object: Runnable {
override fun run() {
b += 3
a += "c"
}
}
r.run()
c()
r.run()
Result.a += a
Result.b += b
}
// FILE: inlineSite.kt
// COMMON_COROUTINES_TEST
import COROUTINES_PACKAGE.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object: Continuation<Unit> {
override val context: CoroutineContext
get() = EmptyCoroutineContext
override fun resume(value: Unit) {
}
override fun resumeWithException(exception: Throwable) {
throw exception
}
})
}
suspend fun dummy() {
val local0 = 0
val local1 = 0
val local2 = 0
val local3 = 0
val local4 = 0
val local5 = 0
val local6 = 0
val local7 = 0
val local8 = 0
val local9 = 0
val local10 = 0
val local11 = 0
val local12 = 0
val local13 = 0
val local14 = 0
val local15 = 0
val local16 = 0
val local17 = 0
val local18 = 0
val local19 = 0
val local20 = 0
val local21 = 0
val local22 = 0
}
suspend fun inlineSite() {
inlineMe {
dummy()
dummy()
}
if (Result.a != "aa" || Result.b != 2) throw RuntimeException("FAIL 1")
noinlineMe {
dummy()
dummy()
}
if (Result.a != "aabb" || Result.b != 6) throw RuntimeException("FAIL 2")
crossinlineMe {
dummy()
dummy()
}
if (Result.a != "aabbcc" || Result.b != 12) throw RuntimeException("FAIL 3")
}
fun box(): String {
builder {
inlineSite()
}
return "OK"
}