Fix [#KT-23921]

* make name collector in inliner process handle JsCatch
 * visit JsParameter during live analyser in coroutine transformer
This commit is contained in:
Roman Artemev
2018-07-20 19:12:45 +03:00
committed by Roman Artemev
parent 31c968123c
commit eb420a1e0f
8 changed files with 95 additions and 0 deletions
@@ -0,0 +1,39 @@
// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
import helpers.*
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
class Controller {
var result = "FAIL"
}
fun faz(): String { throw IllegalStateException("OK") }
inline fun exceptionGet(a: () -> String): String {
try {
return a()
} catch (e: Throwable) {
return e.message!!
}
}
suspend fun baz() {}
suspend fun Controller.bar() {
result = exceptionGet { faz() }
exceptionGet { baz(); "ignored" }
}
fun builder(c: suspend Controller.() -> Unit): String {
val controller = Controller()
c.startCoroutine(controller, EmptyContinuation)
return controller.result
}
fun box(): String {
return builder() { bar() }
}
@@ -5304,6 +5304,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/beginWithException.kt", "kotlin.coroutines");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("coercionToUnit.kt")
public void testCoercionToUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/coercionToUnit.kt", "kotlin.coroutines.experimental");
@@ -5304,6 +5304,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/beginWithException.kt", "kotlin.coroutines");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("coercionToUnit.kt")
public void testCoercionToUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/coercionToUnit.kt", "kotlin.coroutines.experimental");
@@ -5304,6 +5304,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/beginWithException.kt", "kotlin.coroutines");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("coercionToUnit.kt")
public void testCoercionToUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/coercionToUnit.kt", "kotlin.coroutines.experimental");
@@ -288,6 +288,12 @@ fun List<CoroutineBlock>.collectVariablesSurvivingBetweenBlocks(localVariables:
}
override fun visitParameter(x: JsParameter) {
varDeclaredIn[x.name]?.add(blockIndex)
varDefinedIn[x.name]?.add(blockIndex)
super.visitParameter(x)
}
override fun visitBinaryExpression(x: JsBinaryOperation) {
val lhs = x.arg1
if (x.operator.isAssignment && lhs is JsNameRef) {
@@ -104,6 +104,11 @@ fun collectDefinedNames(scope: JsNode): Set<JsName> {
super.visitExpressionStatement(x)
}
override fun visitCatch(x: JsCatch) {
names += x.parameter.name
super.visitCatch(x)
}
// Skip function expression, since it does not introduce name in scope of containing function.
// The only exception is function statement, that is handled with the code above.
override fun visitFunction(x: JsFunction) { }
@@ -5004,6 +5004,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/beginWithException.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("coercionToUnit.kt")
public void testCoercionToUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/coercionToUnit.kt", "kotlin.coroutines.experimental");
@@ -5069,6 +5069,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/beginWithException.kt", "kotlin.coroutines");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("catchWithInlineInsideSuspend.kt")
public void testCatchWithInlineInsideSuspend_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/catchWithInlineInsideSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("coercionToUnit.kt")
public void testCoercionToUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/coercionToUnit.kt", "kotlin.coroutines.experimental");