Fix codegen problem with safe-call on suspension point with two receivers

#KT-16145 Fixed
This commit is contained in:
Denis Zharkov
2017-02-03 16:42:19 +03:00
parent a10c6f00f9
commit cc7f0e2d83
9 changed files with 249 additions and 4 deletions
@@ -0,0 +1,48 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
import kotlin.test.assertEquals
class A(val w: String) {
suspend fun String.ext(): String = suspendCoroutineOrReturn {
x ->
x.resume(this + w)
COROUTINE_SUSPENDED
}
}
suspend fun A.coroutinebug(v: String?): String {
val r = v?.ext()
if (r == null) return "null"
return r
}
suspend fun A.coroutinebug2(v: String?): String {
val r = v?.ext() ?: "null"
return r
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = "fail 2"
builder {
val a = A("K")
val x1 = a.coroutinebug(null)
if (x1 != "null") throw RuntimeException("fail 1: $x1")
val x2 = a.coroutinebug(null)
if (x2 != "null") throw RuntimeException("fail 2: $x2")
val x3 = a.coroutinebug2(null)
if (x3 != "null") throw RuntimeException("fail 3: $x3")
result = a.coroutinebug2("O")
}
return result
}
@@ -0,0 +1,51 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
import kotlin.test.assertEquals
class A(val w: String) {
suspend fun Long.ext(): String = suspendCoroutineOrReturn {
x ->
x.resume(this.toString() + w)
COROUTINE_SUSPENDED
}
}
suspend fun A.coroutinebug(v: Long?): String {
val r = v?.ext()
if (r == null) return "null"
return r
}
suspend fun A.coroutinebug2(v: Long?): String {
val r = v?.ext() ?: "null"
return r
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = "fail 2"
builder {
val a = A("#test")
val x1 = a.coroutinebug(null)
if (x1 != "null") throw RuntimeException("fail 1: $x1")
val x2 = a.coroutinebug(123456789012345)
if (x2 != "123456789012345#test") throw RuntimeException("fail 2: $x2")
val x3 = a.coroutinebug2(null)
if (x3 != "null") throw RuntimeException("fail 3: $x3")
val x4 = a.coroutinebug2(123456789012345)
if (x4 != "123456789012345#test") throw RuntimeException("fail 4: $x4")
result = "OK"
}
return result
}