diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt index d63bfff08ac..8233d78b26f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt @@ -1272,10 +1272,10 @@ class ControlFlowGraphBuilder { // (4)... in catch, i.e., re-throw. exitTargetsForTry.top() } else { - // (4)... in try-main. We already have: - // edges from try-main enter node to each catch clause enter node and - // edges from catch clause enter node to exit target (w/ UncaughtExceptionPath) - return + // (4)... in try-main. Route to exit of try main block. + // We already have edges from the exit of try main block to each catch clause. + // This edge makes the remaining part of try main block, e.g., following `when` branches, marked as dead. + tryMainExitNodes.top() } } // (3)... within finally. diff --git a/compiler/testData/codegen/boxInline/complexStack/spillConstructorArgumentsAndInlineLambdaParameter.kt b/compiler/testData/codegen/boxInline/complexStack/spillConstructorArgumentsAndInlineLambdaParameter.kt index f1fa76d5ff2..e26a1145b36 100644 --- a/compiler/testData/codegen/boxInline/complexStack/spillConstructorArgumentsAndInlineLambdaParameter.kt +++ b/compiler/testData/codegen/boxInline/complexStack/spillConstructorArgumentsAndInlineLambdaParameter.kt @@ -1,3 +1,4 @@ +// IGNORE_FIR_DIAGNOSTICS // FILE: 1.kt class A(val s: String) diff --git a/compiler/testData/diagnostics/tests/initializedAfterRethrow.fir.kt b/compiler/testData/diagnostics/tests/initializedAfterRethrow.fir.kt new file mode 100644 index 00000000000..3b9a04d7c83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/initializedAfterRethrow.fir.kt @@ -0,0 +1,222 @@ +fun foo(): Int = 42 + +object ThrowInTryWithCatch { + private val p: String + + init { + try { + throw Exception() + } catch (e: Exception) { + } + p = "OK" + } +} + +object ThrowInTryWithCatchAndFinally { + private val p: String + + init { + try { + throw Exception() + } catch (e: Exception) { + } finally { + } + p = "OK" + } +} + +object ThrowInFinally { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + } finally { + throw Exception() + } + p = "OK" + } +} + +object RethrowInCatch { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + throw e + } + p = "OK" + } +} + +object RethrowInCatchWithFinally { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + throw e + } finally { + } + p = "OK" + } +} + +object InnerTryWithCatch { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + throw e + } catch (ee: Exception) { + } + } + p = "OK" + } +} + +object InnerTryWithFinally { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + throw e + } finally { + } + } + p = "OK" + } +} + + +object InnerTryWithCatchAndFinally { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + throw e + } catch (ee: Exception) { + } finally { + } + } + p = "OK" + } +} + +object InnerCatch { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + foo() + } catch (ee: Exception) { + throw ee + } + } + p = "OK" + } +} + +object InnerCatchWithFinally { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + foo() + } catch (ee: Exception) { + throw ee + } finally { + } + } + p = "OK" + } +} + +object InnerCatchOuterRethrow { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + foo() + } catch (ee: Exception) { + throw e + } + } + p = "OK" + } +} + +object InnerCatchOuterRethrowWithFinally { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + foo() + } catch (ee: Exception) { + throw e + } finally { + } + } + p = "OK" + } +} + +object InnerFinally { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + foo() + } finally { + throw e + } + } + p = "OK" + } +} + +object InnerFinallyWithCatch { + private val p: String + + init { + try { + foo() + } catch (e: Exception) { + try { + foo() + } catch (ee: Exception) { + } finally { + throw e + } + } + p = "OK" + } +} diff --git a/compiler/testData/diagnostics/tests/initializedAfterRethrow.kt b/compiler/testData/diagnostics/tests/initializedAfterRethrow.kt index f3aeb466978..af394e1fa19 100644 --- a/compiler/testData/diagnostics/tests/initializedAfterRethrow.kt +++ b/compiler/testData/diagnostics/tests/initializedAfterRethrow.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL fun foo(): Int = 42 object ThrowInTryWithCatch { diff --git a/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt index 97996bc8fdd..b9d6ac6f20d 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt @@ -40,7 +40,7 @@ fun conditionalThrowInTry_smartcastInTry(a: A) { if (a !is B) { throw AssertionError() } - takeB(a) + takeB(a) } catch (e: Throwable) {} }