[JS BE] Set enclosing exception state in finally block
[Fix KT-28207]
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JS
|
|
||||||
// IGNORE_BACKEND: JVM_IR
|
// IGNORE_BACKEND: JVM_IR
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// COMMON_COROUTINES_TEST
|
||||||
|
import helpers.*
|
||||||
|
import COROUTINES_PACKAGE.*
|
||||||
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
|
|
||||||
|
// Note: This test for issue KT-28207 about infinite loop after throwing exception from finally block
|
||||||
|
|
||||||
|
suspend fun throwHere(): Nothing = throw RuntimeException("Do not catch me")
|
||||||
|
|
||||||
|
fun builder(c: suspend () -> Unit) {
|
||||||
|
c.startCoroutine(EmptyContinuation)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var result = ""
|
||||||
|
|
||||||
|
var count = 0
|
||||||
|
try {
|
||||||
|
builder {
|
||||||
|
try {
|
||||||
|
throwHere()
|
||||||
|
count = 1
|
||||||
|
} finally {
|
||||||
|
if (count == 0) {
|
||||||
|
count = 2
|
||||||
|
result = "O"
|
||||||
|
throw Exception("K")
|
||||||
|
} else if (count == 2) {
|
||||||
|
result = "FAIL: execution gets into infinite loop"
|
||||||
|
} else {
|
||||||
|
result = "FAIL: exception has not been thrown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (x: Exception) {
|
||||||
|
result += x.message
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// COMMON_COROUTINES_TEST
|
||||||
|
import helpers.*
|
||||||
|
import COROUTINES_PACKAGE.*
|
||||||
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
|
|
||||||
|
// Note: This test for issue KT-28207 about infinite loop after throwing exception from finally block
|
||||||
|
|
||||||
|
var resume: () -> Unit = {}
|
||||||
|
|
||||||
|
suspend fun suspendHere(): String = suspendCoroutineUninterceptedOrReturn { cont ->
|
||||||
|
resume = {
|
||||||
|
cont.resumeWithException(RuntimeException("Do not catch me"))
|
||||||
|
}
|
||||||
|
COROUTINE_SUSPENDED
|
||||||
|
}
|
||||||
|
|
||||||
|
fun builder(c: suspend () -> Unit) {
|
||||||
|
c.startCoroutine(EmptyContinuation)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var result = ""
|
||||||
|
|
||||||
|
var count = 0
|
||||||
|
try {
|
||||||
|
builder {
|
||||||
|
try {
|
||||||
|
suspendHere()
|
||||||
|
count = 1
|
||||||
|
} finally {
|
||||||
|
if (count == 0) {
|
||||||
|
count = 2
|
||||||
|
result = "O"
|
||||||
|
throw Exception("K")
|
||||||
|
} else if (count == 2) {
|
||||||
|
result = "FAIL: execution gets into infinite loop"
|
||||||
|
} else {
|
||||||
|
result = "FAIL: exception has not been thrown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resume()
|
||||||
|
} catch (x: Exception) {
|
||||||
|
result += x.message
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
+20
@@ -7623,6 +7623,26 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple_1_2() throws Exception {
|
public void testSimple_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
+20
@@ -7623,6 +7623,26 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple_1_2() throws Exception {
|
public void testSimple_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
+20
@@ -7623,6 +7623,26 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple_1_2() throws Exception {
|
public void testSimple_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
@@ -295,6 +295,7 @@ class CoroutineBodyTransformer(private val context: CoroutineTransformationConte
|
|||||||
// Handle finally node
|
// Handle finally node
|
||||||
if (finallyNode != null) {
|
if (finallyNode != null) {
|
||||||
currentBlock = finallyBlock
|
currentBlock = finallyBlock
|
||||||
|
currentStatements += exceptionState(oldCatchBlock, x)
|
||||||
finallyNode.statements.forEach { it.accept(this) }
|
finallyNode.statements.forEach { it.accept(this) }
|
||||||
generateFinallyExit()
|
generateFinallyExit()
|
||||||
hasFinallyBlocks = true
|
hasFinallyBlocks = true
|
||||||
|
|||||||
+10
@@ -6373,6 +6373,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple_1_3() throws Exception {
|
public void testSimple_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines");
|
||||||
|
|||||||
+20
@@ -7223,6 +7223,26 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinallyWithSuspension.kt")
|
||||||
|
public void testRethrowInFinallyWithSuspension_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinallyWithSuspension.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("rethrowInFinally.kt")
|
||||||
|
public void testRethrowInFinally_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/rethrowInFinally.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple_1_2() throws Exception {
|
public void testSimple_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/stackUnwinding/simple.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
Reference in New Issue
Block a user