Validate label value of coroutine in case of no suspension points

#KT-14718 Fixed
This commit is contained in:
Denis Zharkov
2016-11-09 12:00:33 +03:00
parent 46b91365ba
commit ae70a60a0a
5 changed files with 59 additions and 3 deletions
@@ -74,8 +74,6 @@ class CoroutineTransformerMethodVisitor(
// Add global exception handler
processHandleExceptionCall(methodNode)
if (suspensionPoints.isEmpty()) return
// Spill stack to variables before suspension points, try/catch blocks
FixStackWithLabelNormalizationMethodTransformer().transform(classBuilder.thisName, methodNode)
+21 -1
View File
@@ -35,7 +35,27 @@ fun box(): String {
return "fail 3"
} catch (e: java.lang.IllegalStateException) {
if (e.message != "call to 'resume' before 'invoke' with coroutine") return "fail 4: ${e.message!!}"
return "OK"
}
var result = "OK"
try {
builder1 {
result = "fail 5"
}
return "fail 6"
} catch (e: java.lang.IllegalStateException) {
if (e.message != "call to 'resume' before 'invoke' with coroutine") return "fail 7: ${e.message!!}"
}
try {
builder2 {
result = "fail 8"
}
return "fail 9"
} catch (e: java.lang.IllegalStateException) {
if (e.message != "call to 'resume' before 'invoke' with coroutine") return "fail 10: ${e.message!!}"
return result
}
return "fail"
@@ -0,0 +1,26 @@
class Controller {
var res = 0
operator fun handleResult(x: Int, y: Continuation<Nothing>) {
res = x
}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>): Int {
val controller = Controller()
c(controller).resume(Unit)
return controller.res
}
fun box(): String {
var result = ""
val handledResult = builder {
result = "OK"
56
}
if (handledResult != 56) return "fail 1: $handledResult"
return result
}
@@ -4573,6 +4573,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("noSuspensionPoints.kt")
public void testNoSuspensionPoints() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/noSuspensionPoints.kt");
doTest(fileName);
}
@TestMetadata("nonLocalReturnFromInlineLambda.kt")
public void testNonLocalReturnFromInlineLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/nonLocalReturnFromInlineLambda.kt");
@@ -4573,6 +4573,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("noSuspensionPoints.kt")
public void testNoSuspensionPoints() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/noSuspensionPoints.kt");
doTest(fileName);
}
@TestMetadata("nonLocalReturnFromInlineLambda.kt")
public void testNonLocalReturnFromInlineLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/nonLocalReturnFromInlineLambda.kt");