diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 514b5a25154..f3c6f2932ea 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -25745,6 +25745,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/smartCasts/threeImplicitReceivers.kt"); } + @Test + @TestMetadata("throwInTry.kt") + public void testThrowInTry() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/throwInTry.kt"); + } + @Test @TestMetadata("twoImplicitReceivers.kt") public void testTwoImplicitReceivers() throws Exception { diff --git a/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt new file mode 100644 index 00000000000..97996bc8fdd --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt @@ -0,0 +1,88 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_EXPRESSION + +fun throwInTry_valueInCatch_smartcastAfterTryCatch() { + val s = try { + throw AssertionError() + } catch(e: Throwable) { + "OK" + } + s.length +} + +fun throwInTry_valueInFinally_noSmartcastAfterTryCatchFinally() { + val s = try { + throw AssertionError() + } catch(e: Throwable) { + } finally { + "not enough" + } + s.length +} + +fun throwInTry_valueInCatchAndFinally_smartcastAfterTryCatchFinally() { + val s = try { + throw AssertionError() + } catch(e: Throwable) { + "OK" + } finally { + "really" + } + s.length +} + +interface A +interface B : A + +fun takeB(b: B) {} + +fun conditionalThrowInTry_smartcastInTry(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + takeB(a) + } catch (e: Throwable) {} +} + +fun conditionalThrowInTry_noSmartcastAfterTryCatch(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) {} + takeB(a) +} + +fun conditionalThrowInTry_rethrow_smartcastAfterTryCatch(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) { + throw e + } + takeB(a) +} + +fun conditionalThrowInTry_rethrow_smartcastAfterTryCatchFinally(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) { + throw e + } finally {} + takeB(a) +} + +fun conditionalThrowInTry_rethrow_noSmartcastInFinally(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) { + throw e + } finally { + takeB(a) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/throwInTry.kt b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.kt new file mode 100644 index 00000000000..16334e0df4a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.kt @@ -0,0 +1,88 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_EXPRESSION + +fun throwInTry_valueInCatch_smartcastAfterTryCatch() { + val s = try { + throw AssertionError() + } catch(e: Throwable) { + "OK" + } + s.length +} + +fun throwInTry_valueInFinally_noSmartcastAfterTryCatchFinally() { + val s = try { + throw AssertionError() + } catch(e: Throwable) { + } finally { + "not enough" + } + s.length +} + +fun throwInTry_valueInCatchAndFinally_smartcastAfterTryCatchFinally() { + val s = try { + throw AssertionError() + } catch(e: Throwable) { + "OK" + } finally { + "really" + } + s.length +} + +interface A +interface B : A + +fun takeB(b: B) {} + +fun conditionalThrowInTry_smartcastInTry(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + takeB(a) + } catch (e: Throwable) {} +} + +fun conditionalThrowInTry_noSmartcastAfterTryCatch(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) {} + takeB(a) +} + +fun conditionalThrowInTry_rethrow_smartcastAfterTryCatch(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) { + throw e + } + takeB(a) +} + +fun conditionalThrowInTry_rethrow_smartcastAfterTryCatchFinally(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) { + throw e + } finally {} + takeB(a) +} + +fun conditionalThrowInTry_rethrow_noSmartcastInFinally(a: A) { + try { + if (a !is B) { + throw AssertionError() + } + } catch (e: Throwable) { + throw e + } finally { + takeB(a) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/throwInTry.txt b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.txt new file mode 100644 index 00000000000..4bd9bcd341c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.txt @@ -0,0 +1,23 @@ +package + +public fun conditionalThrowInTry_noSmartcastAfterTryCatch(/*0*/ a: A): kotlin.Unit +public fun conditionalThrowInTry_rethrow_noSmartcastInFinally(/*0*/ a: A): kotlin.Unit +public fun conditionalThrowInTry_rethrow_smartcastAfterTryCatch(/*0*/ a: A): kotlin.Unit +public fun conditionalThrowInTry_rethrow_smartcastAfterTryCatchFinally(/*0*/ a: A): kotlin.Unit +public fun conditionalThrowInTry_smartcastInTry(/*0*/ a: A): kotlin.Unit +public fun takeB(/*0*/ b: B): kotlin.Unit +public fun throwInTry_valueInCatchAndFinally_smartcastAfterTryCatchFinally(): kotlin.Unit +public fun throwInTry_valueInCatch_smartcastAfterTryCatch(): kotlin.Unit +public fun throwInTry_valueInFinally_noSmartcastAfterTryCatchFinally(): kotlin.Unit + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B : A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index d8d2729b2a3..2d95ffeb026 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -25835,6 +25835,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/threeImplicitReceivers.kt"); } + @Test + @TestMetadata("throwInTry.kt") + public void testThrowInTry() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/throwInTry.kt"); + } + @Test @TestMetadata("twoImplicitReceivers.kt") public void testTwoImplicitReceivers() throws Exception {