From ab464ea86e658378bc2db298b560fd7c0c544108 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 26 Jan 2017 16:33:08 +0100 Subject: [PATCH] Fix for KT-15726: Kotlin can't compile nested try-catch with return #KT-15726 Fixed --- .../LabelNormalizationMethodTransformer.kt | 2 ++ .../codegen/box/controlStructures/kt15726.kt | 26 +++++++++++++++++++ .../controlStructures/kt15726.txt | 6 +++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++++ ...LightAnalysisModeCodegenTestGenerated.java | 6 +++++ .../semantics/JsCodegenBoxTestGenerated.java | 6 +++++ 7 files changed, 58 insertions(+) create mode 100644 compiler/testData/codegen/box/controlStructures/kt15726.kt create mode 100644 compiler/testData/codegen/light-analysis/controlStructures/kt15726.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/LabelNormalizationMethodTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/LabelNormalizationMethodTransformer.kt index d40624659c3..26a658a122d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/LabelNormalizationMethodTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/LabelNormalizationMethodTransformer.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.codegen.optimization +import org.jetbrains.kotlin.codegen.optimization.common.removeEmptyCatchBlocks import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer import org.jetbrains.org.objectweb.asm.Label import org.jetbrains.org.objectweb.asm.tree.* @@ -34,6 +35,7 @@ class LabelNormalizationMethodTransformer : MethodTransformer() { rewriteNonLabelInstructions() rewriteTryCatchBlocks() rewriteLocalVars() + methodNode.removeEmptyCatchBlocks() } } diff --git a/compiler/testData/codegen/box/controlStructures/kt15726.kt b/compiler/testData/codegen/box/controlStructures/kt15726.kt new file mode 100644 index 00000000000..eb4e336f3e9 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/kt15726.kt @@ -0,0 +1,26 @@ + +fun nyCompiler() { + try { + return + } + catch (e: Exception) {} + finally { + try {} catch (e: Exception) {} + } +} + + +fun nyCompiler2() { + try { + return + } + finally { + try {} catch (e: Exception) {} + } +} + +fun box(): String { + nyCompiler() + nyCompiler2() + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/light-analysis/controlStructures/kt15726.txt b/compiler/testData/codegen/light-analysis/controlStructures/kt15726.txt new file mode 100644 index 00000000000..8699303a76f --- /dev/null +++ b/compiler/testData/codegen/light-analysis/controlStructures/kt15726.txt @@ -0,0 +1,6 @@ +@kotlin.Metadata +public final class Kt15726Kt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method nyCompiler(): void + public final static method nyCompiler2(): void +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 2746dfb4d1a..281e208000e 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -4103,6 +4103,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt15726.kt") + public void testKt15726() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt15726.kt"); + doTest(fileName); + } + @TestMetadata("kt1688.kt") public void testKt1688() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt1688.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index cd5727f6353..66b03c73482 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -4103,6 +4103,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt15726.kt") + public void testKt15726() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt15726.kt"); + doTest(fileName); + } + @TestMetadata("kt1688.kt") public void testKt1688() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt1688.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index 529e35301da..1c56ad44078 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -4103,6 +4103,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis doTest(fileName); } + @TestMetadata("kt15726.kt") + public void testKt15726() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt15726.kt"); + doTest(fileName); + } + @TestMetadata("kt1688.kt") public void testKt1688() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt1688.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index bd83aa1fd49..1cf59d826d6 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -4752,6 +4752,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("kt15726.kt") + public void testKt15726() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt15726.kt"); + doTest(fileName); + } + @TestMetadata("kt1688.kt") public void testKt1688() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt1688.kt");