committed by
GitHub
parent
ef1388e514
commit
67f553d503
+4
-3
@@ -338,11 +338,12 @@ internal class NativeSuspendFunctionsLowering(ctx: Context): AbstractSuspendFunc
|
||||
suspendCall = newChildren[2]
|
||||
}
|
||||
expression.isSuspendCall -> {
|
||||
val lastChild = newChildren.last()
|
||||
if (lastChild != null) {
|
||||
val lastChildIndex = newChildren.indexOfLast { it != null }
|
||||
if (lastChildIndex != -1) {
|
||||
// Save state as late as possible.
|
||||
val lastChild = newChildren[lastChildIndex]!!
|
||||
calledSaveState = true
|
||||
newChildren[numberOfChildren - 1] =
|
||||
newChildren[lastChildIndex] =
|
||||
irBlock(lastChild) {
|
||||
if (lastChild.isPure()) {
|
||||
+irCall(saveState)
|
||||
|
||||
@@ -1622,6 +1622,10 @@ task coroutines_correctOrder1(type: KonanLocalTest) {
|
||||
source = "codegen/coroutines/correctOrder1.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_chain(type: KonanLocalTest) {
|
||||
source = "codegen/coroutines/controlFlow_chain.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_if1(type: KonanLocalTest) {
|
||||
goldValue = "f1\ns1\nf3\n84\n"
|
||||
source = "codegen/coroutines/controlFlow_if1.kt"
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.coroutines.controlFlow_chain
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
// See https://github.com/JetBrains/kotlin-native/issues/3476
|
||||
@Test fun runTest() {
|
||||
var result = 0
|
||||
builder {
|
||||
foo().bar()
|
||||
result = 1
|
||||
}
|
||||
assertEquals(1, result)
|
||||
}
|
||||
|
||||
class Foo {
|
||||
suspend fun bar() {
|
||||
suspendHere()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun foo() = Foo()
|
||||
Reference in New Issue
Block a user