From 17b5e465479c82979da6afe550832c421e6fcd41 Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Mon, 25 Apr 2022 14:55:04 +0200 Subject: [PATCH] [FE1.0] Fix CFG for inline function calls in finally blocks. The body of the InlinedLocalFunctionDeclarationInstruction was not copied. That confuses the information on the exceptional edge with the information on the normal edge. ^KT-52131 Fixed --- ...DiagnosisCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ .../FirOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...dFrontendDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../InlinedLocalFunctionDeclarationInstruction.kt | 4 ++-- .../diagnostics/tests/controlFlowAnalysis/kt52131.kt | 10 ++++++++++ .../diagnostics/tests/controlFlowAnalysis/kt52131.txt | 3 +++ .../kotlin/test/runners/DiagnosticTestGenerated.java | 6 ++++++ 7 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index f9d0af0c8f7..c12d0437f6f 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -5722,6 +5722,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt"); } + @Test + @TestMetadata("kt52131.kt") + public void testKt52131() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt"); + } + @Test @TestMetadata("kt607.kt") public void testKt607() throws Exception { 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 b53a309bd22..fd705961529 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 @@ -5722,6 +5722,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt"); } + @Test + @TestMetadata("kt52131.kt") + public void testKt52131() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt"); + } + @Test @TestMetadata("kt607.kt") public void testKt607() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index e06077499b1..421afa7ecb1 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -5722,6 +5722,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt"); } + @Test + @TestMetadata("kt52131.kt") + public void testKt52131() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt"); + } + @Test @TestMetadata("kt607.kt") public void testKt607() throws Exception { diff --git a/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/special/InlinedLocalFunctionDeclarationInstruction.kt b/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/special/InlinedLocalFunctionDeclarationInstruction.kt index 3f0ca93644e..14f4f0045cf 100644 --- a/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/special/InlinedLocalFunctionDeclarationInstruction.kt +++ b/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/special/InlinedLocalFunctionDeclarationInstruction.kt @@ -30,11 +30,11 @@ class InlinedLocalFunctionDeclarationInstruction( blockScope: BlockScope, val kind: EventOccurrencesRange ) : LocalFunctionDeclarationInstruction(element, body, blockScope) { - override fun createCopy(): InstructionImpl = InlinedLocalFunctionDeclarationInstruction(element, body, blockScope, kind) + override fun createCopy(): InstructionImpl = InlinedLocalFunctionDeclarationInstruction(element, body.copy(), blockScope, kind) override fun accept(visitor: InstructionVisitor) = visitor.visitInlinedLocalFunctionDeclarationInstruction(this) override fun accept(visitor: InstructionVisitorWithResult): R = visitor.visitInlinedFunctionDeclarationInstruction(this) override fun toString(): String = "inlined(${render(element)})" -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt new file mode 100644 index 00000000000..8fd24f820c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt @@ -0,0 +1,10 @@ +// FIR_IDENTICAL + +fun foo(): Int { + var result = 0 + try { + } finally { + 42.let { } + } + return result +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.txt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.txt new file mode 100644 index 00000000000..b02182627c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.txt @@ -0,0 +1,3 @@ +package + +public fun foo(): kotlin.Int 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 b8b03e1dcd4..efd855de792 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 @@ -5728,6 +5728,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt"); } + @Test + @TestMetadata("kt52131.kt") + public void testKt52131() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt52131.kt"); + } + @Test @TestMetadata("kt607.kt") public void testKt607() throws Exception {