Fix suspend function with default argument

In JS BE, fix translation of suspend function with default argument
inherited from interface.

See KT-16658
This commit is contained in:
Alexey Andreev
2017-03-20 19:23:18 +03:00
parent 6ba3812582
commit 0606ebe0dc
8 changed files with 166 additions and 6 deletions
@@ -0,0 +1,78 @@
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
fun box(): String {
async {
O.foo()
O.foo("second")
}
while (!finished) {
result += "--;"
proceed()
}
finished = false
asyncSuspend {
O.foo()
O.foo("second")
}
while (!finished) {
result += "--;"
proceed()
}
val expected = "before(first);--;after(first);before(second);--;after(second);--;done;"
if (result != expected + expected) return "fail: $result"
return "OK"
}
interface I {
suspend fun foo(x: String = "first")
}
object O : I {
override suspend fun foo(x: String) {
result += "before($x);"
sleep()
result += "after($x);"
}
}
suspend fun sleep(): Unit = suspendCoroutine { c ->
proceed = { c.resume(Unit) }
}
fun async(f: suspend () -> Unit) {
f.startCoroutine(object : Continuation<Unit> {
override fun resume(x: Unit) {
proceed = {
result += "done;"
finished = true
}
}
override fun resumeWithException(x: Throwable) {}
override val context = EmptyCoroutineContext
})
}
fun asyncSuspend(f: suspend () -> Unit) {
val coroutine = f.createCoroutine(object : Continuation<Unit> {
override fun resume(x: Unit) {
proceed = {
result += "done;"
finished = true
}
}
override fun resumeWithException(x: Throwable) {}
override val context = EmptyCoroutineContext
})
coroutine.resume(Unit)
}
var result = ""
var proceed: () -> Unit = { }
var finished = false