Files
kotlin-fork/compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.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

86 lines
3.1 KiB
Kotlin
Vendored

// FILE: inlined.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
suspend inline fun inlineMe(c: suspend (String) -> String, d: suspend () -> String): String {
return c(try { d() } catch (e: Exception) { "Exception 1 ${e.message}" })
}
suspend inline fun noinlineMe(noinline c: suspend (String) -> String, noinline d: suspend () -> String): String {
return c(try { d() } catch (e: Exception) { "Exception 1 ${e.message}" })
}
suspend inline fun crossinlineMe(crossinline c: suspend (String) -> String, crossinline d: suspend () -> String): String {
return c(try { d() } catch (e: Exception) { "Exception 1 ${e.message}" })
}
// 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 yieldString(s: String) = s
suspend fun throwException(s: String): String {
throw RuntimeException(s)
}
suspend fun inlineSite() {
var res = inlineMe({ it }) { yieldString("OK") }
if (res != "OK") throw RuntimeException("FAIL 1: $res")
res = inlineMe({ it }) { throwException("OK") }
if (res != "Exception 1 OK") throw RuntimeException("FAIL 2: $res")
res = noinlineMe({ it }) { yieldString("OK") }
if (res != "OK") throw RuntimeException("FAIL 3: $res")
res = noinlineMe({ it }) { throwException("OK") }
if (res != "Exception 1 OK") throw RuntimeException("FAIL 4: $res")
res = crossinlineMe({ it }) { yieldString("OK") }
if (res != "OK") throw RuntimeException("FAIL 5: $res")
res = crossinlineMe({ it }) { throwException("OK") }
if (res != "Exception 1 OK") throw RuntimeException("FAIL 6: $res")
res = inlineMe({ try {yieldString(it) } catch (e: Exception) { yieldString("Exception 2 $it") } }) { yieldString("OK") }
if (res != "OK") throw RuntimeException("FAIL 7: $res")
res = inlineMe({ try {throwException(it) } catch (e: Exception) { yieldString("Exception 2 $it") } }) { yieldString("OK") }
if (res != "Exception 2 OK") throw RuntimeException("FAIL 8: $res")
res = noinlineMe({ try {yieldString(it) } catch (e: Exception) { yieldString("Exception 2 $it") } }) { yieldString("OK") }
if (res != "OK") throw RuntimeException("FAIL 9: $res")
res = noinlineMe({ try {throwException(it) } catch (e: Exception) { yieldString("Exception 2 $it") } }) { yieldString("OK") }
if (res != "Exception 2 OK") throw RuntimeException("FAIL 10: $res")
res = crossinlineMe({ try {yieldString(it) } catch (e: Exception) { yieldString("Exception 2 $it") } }) { yieldString("OK") }
if (res != "OK") throw RuntimeException("FAIL 11: $res")
res = crossinlineMe({ try {throwException(it) } catch (e: Exception) { yieldString("Exception 2 $it") } }) { yieldString("OK") }
if (res != "Exception 2 OK") throw RuntimeException("FAIL 12: $res")
}
fun box(): String {
builder {
inlineSite()
}
return "OK"
}