Fix accessor generation for suspend functions

1. JVM view of suspend accessors must be also an instance of AccessorForFunctionDescriptor,
thus `createSubstitutedCopy` should be correctly overidden.

2. accessibleFunctionDescriptor should unwap the initial suspend descriptor,
for the same reasons as for type aliases constructors and etc:
these descriptors are used as keys of the map of accessors, so
to avoid duplication for suspend view and initial suspend descriptor,
we always use the latter one as a key.

 #KT-15907 Fixed
 #KT-15935 Fixed
This commit is contained in:
Denis Zharkov
2017-01-24 12:09:20 +03:00
parent 0693bd6b62
commit 9ca9a988a6
10 changed files with 217 additions and 0 deletions
@@ -0,0 +1,43 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
class X {
var res = ""
suspend fun execute() {
a()
b()
}
private suspend fun a() {
res += suspendThere("O")
res += suspendThere("K")
}
private suspend fun b() {
res += suspendThere("5")
res += suspendThere("6")
}
}
suspend fun suspendThere(v: String): String = suspendCoroutineOrReturn { x ->
x.resume(v)
SUSPENDED_MARKER
}
fun builder(c: suspend X.() -> Unit) {
c.startCoroutine(X(), EmptyContinuation)
}
fun box(): String {
var result = ""
builder {
execute()
result = res
}
if (result != "OK56") return "fail 1: $result"
return "OK"
}
@@ -0,0 +1,30 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
var x = true
private suspend fun foo(): String {
if (x) {
return suspendCoroutineOrReturn<String> {
it.resume("OK")
SUSPENDED_MARKER
}
}
return "fail"
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var res = ""
builder {
res = foo()
}
return res
}