This commit is contained in:
SvyatoslavScherbina
2019-11-01 11:16:11 +03:00
committed by GitHub
parent ef1388e514
commit 67f553d503
3 changed files with 51 additions and 3 deletions
@@ -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)
+4
View File
@@ -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()