diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot index 0969a5fbcef..3cce0048a67 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot @@ -246,7 +246,7 @@ digraph propertiesAndInitBlocks_kt { 28 -> {48 34} [color=green]; 28 -> {48 34} [style=dashed]; 29 -> {30}; - 30 -> {33}; + 30 -> {81}; 30 -> {31} [style=dotted]; 31 -> {32} [style=dotted]; 32 -> {33} [style=dotted]; 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 e322c34ef36..3576738c337 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 @@ -270,7 +270,9 @@ class ControlFlowGraphBuilder { val exitNode = createFunctionExitNode(anonymousFunction).also { exitsOfAnonymousFunctions[symbol] = it exitTargetsForReturn.push(it) - exitTargetsForTry.push(it) + if (!invocationKind.isInPlace) { + exitTargetsForTry.push(it) + } } if (invocationKind.hasTowardEdge) { @@ -299,13 +301,16 @@ class ControlFlowGraphBuilder { else -> false } + private val EventOccurrencesRange?.isInPlace: Boolean + get() = this != null + fun exitAnonymousFunction(anonymousFunction: FirAnonymousFunction): Triple { - - val symbol = anonymousFunction.symbol val exitNode = exitsOfAnonymousFunctions.remove(symbol)!!.also { require(it == exitTargetsForReturn.pop()) - require(it == exitTargetsForTry.pop()) + if (!anonymousFunction.invocationKind.isInPlace) { + require(it == exitTargetsForTry.pop()) + } } popAndAddEdge(exitNode) exitNode.updateDeadStatus() diff --git a/compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.fir.kt deleted file mode 100644 index 85adce7df3a..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -class A { - fun test() { - val a: A - synchronized(this) { - if (bar()) throw RuntimeException() - a = A() - } - a.bar() - } - - fun bar() = false -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.kt b/compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.kt index 18596c5430f..9f592fa20b0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class A { fun test() { val a: A diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt index 20b4846bdb2..a942e8d5bfb 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt @@ -30,7 +30,7 @@ fun innerTryCatchInitializes() { } } // Can get here only when inlined lambda exited properly, i.e. x is initialized - x.inc() + x.inc() outerComputation() } catch (e: java.lang.Exception) { @@ -44,4 +44,4 @@ fun innerTryCatchInitializes() { } // Here x=I because outer try-catch either exited normally (x=I) or catched exception (x=I, with reassingment, though) x.inc() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt index 61c2f902434..3adc7cc800c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt @@ -26,7 +26,7 @@ fun throwIfNotCalled() { } // x *is* initialized here, because if myRun was never called -> exception // were thrown and control flow wouldn't be here - println(x) + println(x) } fun catchThrowIfNotCalled() { @@ -45,4 +45,4 @@ fun catchThrowIfNotCalled() { // x *isn't* initialized here! println(x) -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt index 2e864fbe2f3..b0914fa713b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt @@ -43,7 +43,7 @@ fun possibleReassignmentInTryCatch() { } x.inc() } - x.inc() + x.inc() } fun tryCatchOuter() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt index b1bedb3fced..b5e2d6fab7e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt @@ -98,7 +98,7 @@ class DefiniteInitializationAfterThrow { if (bar()) throw RuntimeException() a = 42 } - a.hashCode() + a.hashCode() } fun bar() = false } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/controlFlow/initialization/pos/3.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/controlFlow/initialization/pos/3.fir.kt index 54dd51278f6..78ab2981a0e 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/controlFlow/initialization/pos/3.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/controlFlow/initialization/pos/3.fir.kt @@ -147,7 +147,7 @@ fun case_9() { } throw Exception() } - println(x.inc()) + println(x.inc()) } // TESTCASE NUMBER: 10