mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
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
63 lines
1.7 KiB
Kotlin
Vendored
63 lines
1.7 KiB
Kotlin
Vendored
// COMMON_COROUTINES_TEST
|
|
suspend fun empty() {}
|
|
suspend fun withoutReturn() { empty() }
|
|
suspend fun withReturn() { return empty() }
|
|
suspend fun notTailCall() { empty(); empty() }
|
|
suspend fun lambdaAsParameter(c: suspend ()->Unit) { c() }
|
|
suspend fun lambdaAsParameterNotTailCall(c: suspend ()->Unit) { c(); c() }
|
|
suspend fun lambdaAsParameterReturn(c: suspend ()->Unit) { return c() }
|
|
suspend fun returnsInt() = 42
|
|
// This should not be tail-call, since the caller should push Unit.INSTANCE on stack
|
|
suspend fun callsIntNotTailCall() { returnsInt() }
|
|
suspend fun multipleExitPoints(b: Boolean) { if (b) empty() else withoutReturn() }
|
|
suspend fun multipleExitPointsNotTailCall(b: Boolean) { if (b) empty() else returnsInt() }
|
|
|
|
fun ordinary() = 1
|
|
inline fun ordinaryInline() { ordinary() }
|
|
suspend fun multipleExitPointsWithOrdinaryInline(b: Boolean) { if (b) empty() else ordinaryInline() }
|
|
|
|
suspend fun multipleExitPointsWhen(i: Int) {
|
|
when(i) {
|
|
1 -> empty()
|
|
2 -> withReturn()
|
|
3 -> withoutReturn()
|
|
else -> lambdaAsParameter {}
|
|
}
|
|
}
|
|
|
|
suspend fun <T> generic(): T = TODO()
|
|
suspend fun useGenericReturningUnit() {
|
|
generic<Unit>()
|
|
}
|
|
|
|
class Generic<T> {
|
|
suspend fun foo(): T = TODO()
|
|
}
|
|
suspend fun useGenericClass(g: Generic<Unit>) {
|
|
g.foo()
|
|
}
|
|
|
|
suspend fun <T> genericInferType(c: () -> T): T = TODO()
|
|
suspend fun useGenericIngerType() {
|
|
genericInferType {}
|
|
}
|
|
|
|
suspend fun nullableUnit(): Unit? = null
|
|
suspend fun useNullableUnit() {
|
|
nullableUnit()
|
|
}
|
|
|
|
suspend fun useRunRunRunRunRun() {
|
|
run {
|
|
run {
|
|
run {
|
|
run {
|
|
run {
|
|
empty()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|