diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.kt new file mode 100644 index 00000000000..d3f980e3c4d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.kt @@ -0,0 +1,13 @@ +//KT-2369 Variable is not marked as uninitialized in 'finally' section + +fun main(args: Array) { + var x : Int + try { + throw Exception() + } + finally { + doSmth(x + 1) + } +} + +fun doSmth(a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_1.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_1.kt new file mode 100644 index 00000000000..185066d307b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_1.kt @@ -0,0 +1,12 @@ +//KT-2585 Code in try-finally is incorrectly marked as unreachable + +fun foo(x: String): String { + try { + throw RuntimeException() + } finally { + try { + } catch (e: Exception) { + } + return x // <- Wrong UNREACHABLE_CODE + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_2.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_2.kt new file mode 100644 index 00000000000..8b6d9f6ed9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_2.kt @@ -0,0 +1,23 @@ +//KT-2585 Code in try-finally is incorrectly marked as unreachable + +fun foo() { + try { + throw RuntimeException() + } catch (e: Exception) { + return // <- Wrong UNREACHABLE_CODE + } finally { + while (true); + } +} + +fun bar() { + try { + throw RuntimeException() + } catch (e: Exception) { + return // <- Wrong UNREACHABLE_CODE + } finally { + while (cond()); + } +} + +fun cond() = true \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_3.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_3.kt new file mode 100644 index 00000000000..f2f917ceda4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_3.kt @@ -0,0 +1,9 @@ +//KT-2585 Code in try-finally is incorrectly marked as unreachable + +fun foo(x: String): String { + try { + throw RuntimeException() //should be marked as unreachable, but is not + } finally { + throw NullPointerException() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.kt new file mode 100644 index 00000000000..2180b0912e5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.kt @@ -0,0 +1,28 @@ +//KT-2972 Wrong "unused value" warning when finally is present + +import java.io.Closeable + +public inline fun T.use(block: (T)-> R) : R { + var closed = false + try { + return block(this) + } catch (e: Exception) { + closed = true // warning here + try { + this.close() + } catch (closeException: Exception) { + // eat the closeException as we are already throwing the original cause + // and we don't want to mask the real exception + + // TODO on Java 7 we should call + // e.addSuppressed(closeException) + // to work like try-with-resources + // http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html#suppressed-exceptions + } + throw e + } finally { + if (!closed) { + this.close() + } + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 4773e798765..60ceeb7d8b7 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -894,11 +894,36 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.kt"); } + @TestMetadata("kt2369.kt") + public void testKt2369() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.kt"); + } + + @TestMetadata("kt2585_1.kt") + public void testKt2585_1() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_1.kt"); + } + + @TestMetadata("kt2585_2.kt") + public void testKt2585_2() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_2.kt"); + } + + @TestMetadata("kt2585_3.kt") + public void testKt2585_3() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2585_3.kt"); + } + @TestMetadata("kt2845.kt") public void testKt2845() throws Exception { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2845.kt"); } + @TestMetadata("kt2972.kt") + public void testKt2972() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.kt"); + } + @TestMetadata("kt510.kt") public void testKt510() throws Exception { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt");