JS: fix destructuring declaration and increment in coroutines. See KT-16058

This commit is contained in:
Alexey Andreev
2017-01-31 15:22:43 +03:00
parent b929db1b07
commit 97b6c3013a
10 changed files with 74 additions and 36 deletions
@@ -0,0 +1,31 @@
// WITH_RUNTIME
// WITH_COROUTINES
// TARGET_BACKEND: JS
// TODO: looks like this is a bug in JVM backend
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
suspend fun suspendThere(v: A): A = suspendCoroutineOrReturn { x ->
x.resume(v)
COROUTINE_SUSPENDED
}
class A(val value: String) {
operator suspend fun plus(other: A) = suspendThere(A(value + other.value))
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var a = A("O")
builder {
a += A("K")
}
return a.value
}
@@ -1,6 +1,5 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
import kotlin.reflect.KProperty
@@ -34,7 +33,7 @@ class A(val x: String) {
operator suspend fun unaryPlus() = suspendThere(x + "K")
operator suspend fun inc(): A = suspendCoroutineOrReturn { x ->
isProvideDelegateCalled = true
isIncCalled = true
x.resume(this)
COROUTINE_SUSPENDED
}
@@ -86,7 +85,13 @@ suspend fun foo4() {
suspend fun foo6() {
var y = a++
if (y.isIncCalled) throw RuntimeException("fail 7")
if (!y.isIncCalled) throw RuntimeException("fail 7")
}
suspend fun foo7() {
a.isIncCalled = false
val y = ++a
if (!y.isIncCalled) throw RuntimeException("fail 8")
}
fun box(): String {
@@ -98,6 +103,7 @@ fun box(): String {
foo4()
//foo5()
foo6()
foo7()
}
return "OK"
@@ -60,6 +60,7 @@ public final class OperatorsKt {
public final static @org.jetbrains.annotations.Nullable method foo3(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method foo4(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method foo6(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method foo7(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.Continuation): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getA(): A
public final static method setA(@org.jetbrains.annotations.NotNull p0: A): void
public final static @org.jetbrains.annotations.Nullable method suspendThere(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.experimental.Continuation): java.lang.Object