Fix codegen issue of safe-qualified suspension points

#KT-15527 Fixed
This commit is contained in:
Denis Zharkov
2017-01-16 12:46:19 +03:00
parent 8cf8e0fce0
commit fae9cc1c63
9 changed files with 242 additions and 1 deletions
@@ -0,0 +1,40 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
class TestClass {
suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
x.resume("K")
SUSPENDED_MARKER
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun foo(x: String, y: String?) = x + (y ?: "")
fun box(): String {
var result = ""
var instance: TestClass? = null
builder {
result = foo("OK", instance?.suspendHere())
}
if (result != "OK") return "fail 1: $result"
result = ""
instance = TestClass()
builder {
result = foo("O", instance?.suspendHere())
}
if (result != "OK") return "fail 2: $result"
return "OK"
}
@@ -0,0 +1,37 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
class TestClass {
suspend fun toInt(): Int = suspendCoroutineOrReturn { x ->
x.resume(14)
SUSPENDED_MARKER
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
var instance: TestClass? = null
builder {
result = 42 + (instance?.toInt() ?: 0)
}
if (result != 42) return "fail 1: $result"
instance = TestClass()
builder {
result = 42 + (instance?.toInt() ?: 0)
}
if (result != 56) return "fail 2: $result"
return "OK"
}