fc70455877
Now AddContinuationLowering is responsible for both adding continuation classes to suspend functions and adding continuation parameters to them. Because we cannot create a view if inline suspend function is defined in another file, we generate a stub without body when we encounter call to it. And then, when we lower the file containing the function we add the body. This way we have no unlowered views after the lowering. Thus, after the lowering there should be no suspend function, which are not views, therefore, remove VIEW origins. Because transformations of suspend functions can copy them into another object, use attribute as a key inside function to view map.
96 lines
2.1 KiB
Kotlin
Vendored
96 lines
2.1 KiB
Kotlin
Vendored
// FILE: test.kt
|
|
// COMMON_COROUTINES_TEST
|
|
// WITH_RUNTIME
|
|
// WITH_COROUTINES
|
|
// NO_CHECK_LAMBDA_INLINING
|
|
|
|
import COROUTINES_PACKAGE.*
|
|
import helpers.*
|
|
|
|
class Controller {
|
|
var res = "FAIL 1"
|
|
}
|
|
|
|
val defaultController = Controller()
|
|
|
|
suspend inline fun test1(controller: Controller = defaultController, crossinline c: suspend Controller.() -> Unit) {
|
|
controller.c()
|
|
}
|
|
|
|
suspend inline fun test2(controller: Controller = defaultController, crossinline c: suspend Controller.() -> Unit) {
|
|
val l : suspend () -> Unit = {
|
|
controller.c()
|
|
}
|
|
l()
|
|
}
|
|
|
|
interface SuspendRunnable {
|
|
suspend fun run()
|
|
}
|
|
|
|
suspend inline fun test3(controller: Controller = defaultController, crossinline c: suspend Controller.() -> Unit) {
|
|
val sr = object: SuspendRunnable {
|
|
override suspend fun run() {
|
|
controller.c()
|
|
}
|
|
}
|
|
sr.run()
|
|
}
|
|
|
|
// FILE: box.kt
|
|
// COMMON_COROUTINES_TEST
|
|
|
|
import COROUTINES_PACKAGE.*
|
|
import helpers.*
|
|
|
|
fun builder(c: suspend () -> Unit) {
|
|
c.startCoroutine(EmptyContinuation)
|
|
}
|
|
|
|
suspend fun calculate() = "OK"
|
|
|
|
fun box() : String {
|
|
builder {
|
|
test1 {
|
|
res = calculate()
|
|
}
|
|
}
|
|
if (defaultController.res != "OK") return defaultController.res
|
|
defaultController.res = "FAIL 2"
|
|
builder {
|
|
test2 {
|
|
res = calculate()
|
|
}
|
|
}
|
|
if (defaultController.res != "OK") return defaultController.res
|
|
defaultController.res = "FAIL 3"
|
|
builder {
|
|
test3 {
|
|
res = calculate()
|
|
}
|
|
}
|
|
if (defaultController.res != "OK") return defaultController.res
|
|
val controller = Controller()
|
|
controller.res = "FAIL 4"
|
|
builder {
|
|
test1(controller) {
|
|
res = calculate()
|
|
}
|
|
}
|
|
if (controller.res != "OK") return controller.res
|
|
controller.res = "FAIL 5"
|
|
builder {
|
|
test2(controller) {
|
|
res = calculate()
|
|
}
|
|
}
|
|
if (controller.res != "OK") return controller.res
|
|
controller.res = "FAIL 6"
|
|
builder {
|
|
test3(controller) {
|
|
res = calculate()
|
|
}
|
|
}
|
|
return controller.res
|
|
}
|