From df46417cd729f758da1d6dbde56c0a6bbba50924 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 29 Mar 2017 17:31:16 +0300 Subject: [PATCH] JS: fix NPE in incremental compilation Fix NPE when compiling project incrementally and a file which is not recompiled contains try/catch statement --- .../jetbrains/kotlin/js/backend/ast/JsCatch.java | 2 +- .../js/test/semantics/BoxJsTestGenerated.java | 6 ++++++ .../testData/box/incremental/catchScope.kt | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 js/js.translator/testData/box/incremental/catchScope.kt diff --git a/js/js.ast/src/org/jetbrains/kotlin/js/backend/ast/JsCatch.java b/js/js.ast/src/org/jetbrains/kotlin/js/backend/ast/JsCatch.java index 5631d87d1a6..8fa62dc77cb 100644 --- a/js/js.ast/src/org/jetbrains/kotlin/js/backend/ast/JsCatch.java +++ b/js/js.ast/src/org/jetbrains/kotlin/js/backend/ast/JsCatch.java @@ -93,7 +93,7 @@ public class JsCatch extends SourceInfoAwareJsNode implements HasCondition { @NotNull @Override public JsCatch deepCopy() { - JsCatchScope scopeCopy = scope.copy(); + JsCatchScope scopeCopy = scope != null ? scope.copy() : null; JsBlock bodyCopy = AstUtil.deepCopy(body); JsExpression conditionCopy = AstUtil.deepCopy(condition); JsParameter paramCopy = AstUtil.deepCopy(param); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 2e6520a136e..bc11a42ee42 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -3443,6 +3443,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/incremental"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("catchScope.kt") + public void testCatchScope() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/incremental/catchScope.kt"); + doTest(fileName); + } + @TestMetadata("coroutines.kt") public void testCoroutines() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/incremental/coroutines.kt"); diff --git a/js/js.translator/testData/box/incremental/catchScope.kt b/js/js.translator/testData/box/incremental/catchScope.kt new file mode 100644 index 00000000000..8264c676a41 --- /dev/null +++ b/js/js.translator/testData/box/incremental/catchScope.kt @@ -0,0 +1,16 @@ +// FILE: a.kt + +inline fun baz(): String = + try { + "OK" + } + catch (e: Exception) { + "not OK" + } + +// FILE: b.kt +// RECOMPILE + +fun box(): String { + return baz() +} \ No newline at end of file