JS: fix translation of return statement surrounded by try..finally block in suspend lambda. See KT-15625

This commit is contained in:
Alexey Andreev
2017-01-11 14:08:35 +03:00
parent 2907eafa18
commit a016147a79
6 changed files with 83 additions and 10 deletions
@@ -2,11 +2,6 @@
// WITH_COROUTINES
import kotlin.coroutines.*
// Does not work in JVM backend, probably due to bug. It's not clear which behaviour is right.
// TODO: fix the bug and enable for JVM backend
// TARGET_BACKEND: JS
class Controller {
var result = ""
@@ -25,10 +20,18 @@ fun builder(c: suspend Controller.() -> String): String {
return controller.result
}
fun builderUnit(c: suspend Controller.() -> Unit): String {
val controller = Controller()
c.startCoroutine(controller, handleResultContinuation {
controller.result += "return;"
})
return controller.result
}
fun <T> id(value: T) = value
fun box(): String {
val value = builder {
var value = builder {
try {
if (id(23) == 23) {
return@builder suspendAndLog("OK")
@@ -40,7 +43,22 @@ fun box(): String {
result += "afterFinally;"
"shouldNotReach"
}
if (value != "suspend(OK);finally;return(OK);") return "fail: $value"
if (value != "suspend(OK);finally;return(OK);") return "fail1: $value"
value = builderUnit {
try {
if (id(23) == 23) {
suspendAndLog("OK")
return@builderUnit
}
}
finally {
result += "finally;"
}
result += "afterFinally;"
"shouldNotReach"
}
if (value != "suspend(OK);finally;return;") return "fail2: $value"
return "OK"
}
@@ -0,0 +1,30 @@
@kotlin.Metadata
public final class Controller {
private @org.jetbrains.annotations.NotNull field result: java.lang.String
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getResult(): java.lang.String
public final method setResult(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public final @org.jetbrains.annotations.Nullable method suspendAndLog(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
}
@kotlin.Metadata
public final class CoroutineUtilKt {
public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
}
@kotlin.Metadata
public final class EmptyContinuation {
public final static field INSTANCE: EmptyContinuation
private method <init>(): void
public method resume(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void
public method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
}
@kotlin.Metadata
public final class ReturnFromFinallyKt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2): java.lang.String
public final static @org.jetbrains.annotations.NotNull method builderUnit(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2): java.lang.String
public final static method id(p0: java.lang.Object): java.lang.Object
}