From 65fae3bb0c836031c144acefd07a4d77c22d86e4 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 5 Jun 2020 14:20:57 +0300 Subject: [PATCH] [FIR] Fix problem with local classes in anonymous objects --- .../cfg/innerClassInAnonymousObject.dot | 61 +++++++++++++++++++ .../cfg/innerClassInAnonymousObject.kt | 7 +++ .../cfg/innerClassInAnonymousObject.txt | 19 ++++++ .../fir/FirDiagnosticsTestGenerated.java | 5 ++ ...DiagnosticsWithLightTreeTestGenerated.java | 5 ++ .../fir/resolve/dfa/FirDataFlowAnalyzer.kt | 2 +- 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot create mode 100644 compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.txt diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot new file mode 100644 index 00000000000..023097f593f --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot @@ -0,0 +1,61 @@ +digraph innerClassInAnonymousObject_kt { + graph [nodesep=3] + node [shape=box penwidth=2] + edge [penwidth=2] + + subgraph cluster_0 { + color=red + 0 [label="Enter function " style="filled" fillcolor=red]; + 2 [label="Delegated constructor call: super()"]; + 1 [label="Exit function " style="filled" fillcolor=red]; + } + 0 -> {2}; + 2 -> {1}; + + subgraph cluster_1 { + color=red + 3 [label="Enter function " style="filled" fillcolor=red]; + 5 [label="Delegated constructor call: super()"]; + 4 [label="Exit function " style="filled" fillcolor=red]; + } + 3 -> {5}; + 5 -> {4}; + + subgraph cluster_2 { + color=red + 6 [label="Enter function foo" style="filled" fillcolor=red]; + 7 [label="Exit function foo" style="filled" fillcolor=red]; + } + 6 -> {7}; + + subgraph cluster_3 { + color=red + 8 [label="Enter class Nested" style="filled" fillcolor=red]; + 9 [label="Exit class Nested" style="filled" fillcolor=red]; + } + 8 -> {9} [color=green]; + + subgraph cluster_4 { + color=red + 10 [label="Enter class " style="filled" fillcolor=red]; + 11 [label="Exit class " style="filled" fillcolor=red]; + } + 10 -> {11} [color=green]; + + subgraph cluster_5 { + color=red + 14 [label="Enter property" style="filled" fillcolor=red]; + subgraph cluster_6 { + color=blue + 12 [label="Enter function getter" style="filled" fillcolor=red]; + 13 [label="Exit function getter" style="filled" fillcolor=red]; + } + 16 [label="Exit anonymous object"]; + 15 [label="Exit property" style="filled" fillcolor=red]; + } + 14 -> {16}; + 14 -> {0 3 6} [color=red]; + 16 -> {15}; + 12 -> {13}; + +} diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.kt b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.kt new file mode 100644 index 00000000000..54a804a31d7 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.kt @@ -0,0 +1,7 @@ +// !DUMP_CFG + +val x = object { + class Nested { + fun foo() {} + } +} diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.txt b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.txt new file mode 100644 index 00000000000..7611a39a83f --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.txt @@ -0,0 +1,19 @@ +FILE: innerClassInAnonymousObject.kt + public final val x: R|anonymous| = object : R|kotlin/Any| { + private[local] constructor(): R|anonymous| { + super() + } + + local final class Nested : R|kotlin/Any| { + public[local] constructor(): R|.Nested| { + super() + } + + public[local] final fun foo(): R|kotlin/Unit| { + } + + } + + } + + public get(): R|anonymous| diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 35aef32ec2d..1ff00f38da9 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -702,6 +702,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.kt"); } + @TestMetadata("innerClassInAnonymousObject.kt") + public void testInnerClassInAnonymousObject() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.kt"); + } + @TestMetadata("inplaceLambdaInControlFlowExpressions.kt") public void testInplaceLambdaInControlFlowExpressions() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 46b25e9cf9a..04d99918a96 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -702,6 +702,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.kt"); } + @TestMetadata("innerClassInAnonymousObject.kt") + public void testInnerClassInAnonymousObject() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.kt"); + } + @TestMetadata("inplaceLambdaInControlFlowExpressions.kt") public void testInplaceLambdaInControlFlowExpressions() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index 748343504ff..0ca41bf644f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -177,7 +177,7 @@ abstract class FirDataFlowAnalyzer( } fun exitRegularClass(klass: FirRegularClass): ControlFlowGraph { - if (klass.isLocal) return exitLocalClass(klass) + if (klass.isLocal && components.container !is FirClass<*>) return exitLocalClass(klass) return graphBuilder.exitClass(klass) }