[FIR] Fix problem with local classes in anonymous objects

This commit is contained in:
Dmitriy Novozhilov
2020-06-05 14:20:57 +03:00
parent 5b64c0cfe2
commit 65fae3bb0c
6 changed files with 98 additions and 1 deletions
@@ -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 <init>" style="filled" fillcolor=red];
2 [label="Delegated constructor call: super<R|kotlin/Any|>()"];
1 [label="Exit function <init>" style="filled" fillcolor=red];
}
0 -> {2};
2 -> {1};
subgraph cluster_1 {
color=red
3 [label="Enter function <init>" style="filled" fillcolor=red];
5 [label="Delegated constructor call: super<R|kotlin/Any|>()"];
4 [label="Exit function <init>" 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 <anonymous>" style="filled" fillcolor=red];
11 [label="Exit class <anonymous>" 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};
}
@@ -0,0 +1,7 @@
// !DUMP_CFG
val x = object {
class Nested {
fun foo() {}
}
}
@@ -0,0 +1,19 @@
FILE: innerClassInAnonymousObject.kt
public final val x: R|anonymous| = object : R|kotlin/Any| {
private[local] constructor(): R|anonymous| {
super<R|kotlin/Any|>()
}
local final class Nested : R|kotlin/Any| {
public[local] constructor(): R|<anonymous>.Nested| {
super<R|kotlin/Any|>()
}
public[local] final fun foo(): R|kotlin/Unit| {
}
}
}
public get(): R|anonymous|
@@ -702,6 +702,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.kt"); 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") @TestMetadata("inplaceLambdaInControlFlowExpressions.kt")
public void testInplaceLambdaInControlFlowExpressions() throws Exception { public void testInplaceLambdaInControlFlowExpressions() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.kt");
@@ -702,6 +702,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.kt"); 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") @TestMetadata("inplaceLambdaInControlFlowExpressions.kt")
public void testInplaceLambdaInControlFlowExpressions() throws Exception { public void testInplaceLambdaInControlFlowExpressions() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.kt");
@@ -177,7 +177,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
} }
fun exitRegularClass(klass: FirRegularClass): ControlFlowGraph { 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) return graphBuilder.exitClass(klass)
} }