[K/N] Fix default argument lambda in suspend function code generation

This commit is contained in:
Pavel Kunyavskiy
2023-03-15 19:02:36 +01:00
committed by Space Team
parent 484d3ad273
commit e655e0a809
15 changed files with 156 additions and 0 deletions
@@ -0,0 +1,71 @@
// WITH_STDLIB
// WITH_COROUTINES
// lowered IR can be dependent on file order here, so we will test both
// FILE: A.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
class Controller1 {
suspend fun suspendHere(block : () -> String = { "DEF" }): String = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(block())
COROUTINE_SUSPENDED
}
}
fun builder1(c: suspend Controller1.() -> Unit) {
c.startCoroutine(Controller1(), EmptyContinuation)
}
// FILE: B.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun box(): String {
var result = "FAIL 1"
builder1 {
if (suspendHere() != "DEF") {
result = "FAIL"
return@builder1
}
result = suspendHere { "OK" }
}
if (result != "OK") return result
result = "FAIL 2"
builder2 {
if (suspendHere() != "DEF") {
result = "FAIL"
return@builder2
}
result = suspendHere { "OK" }
}
return result
}
// FILE: C.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
class Controller2 {
suspend fun suspendHere(block : () -> String = { "DEF" }): String = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(block())
COROUTINE_SUSPENDED
}
}
fun builder2(c: suspend Controller2.() -> Unit) {
c.startCoroutine(Controller2(), EmptyContinuation)
}