[FIR] do not create FirParameter for catch parameter

use FirProperty instead

^KT-55034
This commit is contained in:
Ilya Kirillov
2022-11-18 16:38:15 +01:00
parent 9671e20f1f
commit c8e3103af9
24 changed files with 450 additions and 368 deletions
@@ -36,7 +36,7 @@ internal class KtFirSymbolProvider(
psi = psi, psi = psi,
) )
psi.isLoopParameter -> { psi.isLoopParameter || psi.isCatchParameter -> {
firSymbolBuilder.variableLikeBuilder.buildLocalVariableSymbol( firSymbolBuilder.variableLikeBuilder.buildLocalVariableSymbol(
psi.resolveToFirSymbolOfType<FirPropertySymbol>(firResolveSession) psi.resolveToFirSymbolOfType<FirPropertySymbol>(firResolveSession)
) )
@@ -9,4 +9,4 @@ try {
catch (e: R|kotlin/Throwable|) { catch (e: R|kotlin/Throwable|) {
} }
finally { finally {
} }
@@ -3,7 +3,7 @@ FILE: catchParameter.kt
public final fun <T : R|kotlin/Throwable|> test(): R|kotlin/Unit| { public final fun <T : R|kotlin/Throwable|> test(): R|kotlin/Unit| {
try { try {
} }
catch (e: R|kotlin/NullPointerException| = R|java/lang/NullPointerException.NullPointerException|()) { catch (e: R|kotlin/NullPointerException|) {
} }
try { try {
@@ -23,7 +23,7 @@ FILE: catchParameter.kt
try { try {
} }
catch (e: R|kotlin/Int| = Int(5)) { catch (e: R|kotlin/Int|) {
} }
try { try {
+89 -87
View File
@@ -68,40 +68,41 @@ digraph complex_kt {
subgraph cluster_12 { subgraph cluster_12 {
color=blue color=blue
27 [label="Catch enter"]; 27 [label="Catch enter"];
28 [label="Variable declaration: closeException: R|kotlin/Throwable|"];
subgraph cluster_13 { subgraph cluster_13 {
color=blue color=blue
28 [label="Enter block"]; 29 [label="Enter block"];
29 [label="Access variable R|<local>/cause|"]; 30 [label="Access variable R|<local>/cause|"];
30 [label="Smart cast: R|<local>/cause|"]; 31 [label="Smart cast: R|<local>/cause|"];
31 [label="Access variable R|<local>/closeException|"]; 32 [label="Access variable R|<local>/closeException|"];
32 [label="Function call: R|<local>/cause|.R|kotlin/Throwable.addSuppressed|(...)"]; 33 [label="Function call: R|<local>/cause|.R|kotlin/Throwable.addSuppressed|(...)"];
33 [label="Exit block"]; 34 [label="Exit block"];
} }
34 [label="Catch exit"]; 35 [label="Catch exit"];
} }
35 [label="Try expression exit"]; 36 [label="Try expression exit"];
} }
36 [label="Exit block"]; 37 [label="Exit block"];
} }
37 [label="Exit when branch result"]; 38 [label="Exit when branch result"];
38 [label="Enter when branch result"]; 39 [label="Enter when branch result"];
subgraph cluster_14 { subgraph cluster_14 {
color=blue color=blue
39 [label="Enter block"]; 40 [label="Enter block"];
40 [label="Function call: this@R|/closeFinally|.R|/AutoCloseable.close|()"]; 41 [label="Function call: this@R|/closeFinally|.R|/AutoCloseable.close|()"];
41 [label="Exit block"]; 42 [label="Exit block"];
} }
42 [label="Exit when branch result"]; 43 [label="Exit when branch result"];
43 [label="Enter when branch result"]; 44 [label="Enter when branch result"];
subgraph cluster_15 { subgraph cluster_15 {
color=blue color=blue
44 [label="Enter block"]; 45 [label="Enter block"];
45 [label="Exit block"]; 46 [label="Exit block"];
} }
46 [label="Exit when branch result"]; 47 [label="Exit when branch result"];
47 [label="Exit when"]; 48 [label="Exit when"];
} }
48 [label="Jump: ^closeFinally when () { 49 [label="Jump: ^closeFinally when () {
==(this@R|/closeFinally|, Null(null)) -> { ==(this@R|/closeFinally|, Null(null)) -> {
} }
==(R|<local>/cause|, Null(null)) -> { ==(R|<local>/cause|, Null(null)) -> {
@@ -118,10 +119,10 @@ digraph complex_kt {
} }
} }
"]; "];
49 [label="Stub" style="filled" fillcolor=gray]; 50 [label="Stub" style="filled" fillcolor=gray];
50 [label="Exit block" style="filled" fillcolor=gray]; 51 [label="Exit block" style="filled" fillcolor=gray];
} }
51 [label="Exit function closeFinally" style="filled" fillcolor=red]; 52 [label="Exit function closeFinally" style="filled" fillcolor=red];
} }
4 -> {5}; 4 -> {5};
5 -> {6}; 5 -> {6};
@@ -130,12 +131,12 @@ digraph complex_kt {
8 -> {9}; 8 -> {9};
9 -> {10}; 9 -> {10};
10 -> {11}; 10 -> {11};
11 -> {43 12}; 11 -> {44 12};
12 -> {13}; 12 -> {13};
13 -> {14}; 13 -> {14};
14 -> {15}; 14 -> {15};
15 -> {16}; 15 -> {16};
16 -> {38 17}; 16 -> {39 17};
17 -> {18}; 17 -> {18};
18 -> {19}; 18 -> {19};
19 -> {20}; 19 -> {20};
@@ -145,9 +146,9 @@ digraph complex_kt {
23 -> {24}; 23 -> {24};
24 -> {25}; 24 -> {25};
25 -> {26}; 25 -> {26};
26 -> {35 27}; 26 -> {36 27};
27 -> {28}; 27 -> {28};
27 -> {51} [label=onUncaughtException]; 27 -> {52} [label=onUncaughtException];
28 -> {29}; 28 -> {29};
29 -> {30}; 29 -> {30};
30 -> {31}; 30 -> {31};
@@ -157,93 +158,93 @@ digraph complex_kt {
34 -> {35}; 34 -> {35};
35 -> {36}; 35 -> {36};
36 -> {37}; 36 -> {37};
37 -> {47}; 37 -> {38};
38 -> {39}; 38 -> {48};
39 -> {40}; 39 -> {40};
40 -> {41}; 40 -> {41};
41 -> {42}; 41 -> {42};
42 -> {47}; 42 -> {43};
43 -> {44}; 43 -> {48};
44 -> {45}; 44 -> {45};
45 -> {46}; 45 -> {46};
46 -> {47}; 46 -> {47};
47 -> {48}; 47 -> {48};
48 -> {51}; 48 -> {49};
48 -> {49} [style=dotted]; 49 -> {52};
49 -> {50} [style=dotted]; 49 -> {50} [style=dotted];
50 -> {51} [style=dotted]; 50 -> {51} [style=dotted];
51 -> {52} [style=dotted];
subgraph cluster_16 { subgraph cluster_16 {
color=red color=red
52 [label="Enter function firstIsInstanceOrNull" style="filled" fillcolor=red]; 53 [label="Enter function firstIsInstanceOrNull" style="filled" fillcolor=red];
subgraph cluster_17 { subgraph cluster_17 {
color=blue color=blue
53 [label="Enter block"]; 54 [label="Enter block"];
subgraph cluster_18 { subgraph cluster_18 {
color=blue color=blue
54 [label="Enter block"]; 55 [label="Enter block"];
55 [label="Access variable this@R|/firstIsInstanceOrNull|"]; 56 [label="Access variable this@R|/firstIsInstanceOrNull|"];
56 [label="Function call: this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<CapturedType(*)>|>|()"]; 57 [label="Function call: this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<CapturedType(*)>|>|()"];
57 [label="Variable declaration: lval <iterator>: R|kotlin/collections/Iterator<kotlin/Any?>|"]; 58 [label="Variable declaration: lval <iterator>: R|kotlin/collections/Iterator<kotlin/Any?>|"];
subgraph cluster_19 { subgraph cluster_19 {
color=blue color=blue
58 [label="Enter while loop"]; 59 [label="Enter while loop"];
subgraph cluster_20 { subgraph cluster_20 {
color=blue color=blue
59 [label="Enter loop condition"]; 60 [label="Enter loop condition"];
60 [label="Access variable R|<local>/<iterator>|"]; 61 [label="Access variable R|<local>/<iterator>|"];
61 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()"]; 62 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()"];
62 [label="Exit loop condition"]; 63 [label="Exit loop condition"];
} }
subgraph cluster_21 { subgraph cluster_21 {
color=blue color=blue
63 [label="Enter loop block"]; 64 [label="Enter loop block"];
subgraph cluster_22 { subgraph cluster_22 {
color=blue color=blue
64 [label="Enter block"]; 65 [label="Enter block"];
65 [label="Access variable R|<local>/<iterator>|"]; 66 [label="Access variable R|<local>/<iterator>|"];
66 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|kotlin/Any?|>|()"]; 67 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|kotlin/Any?|>|()"];
67 [label="Variable declaration: lval element: R|kotlin/Any?|"]; 68 [label="Variable declaration: lval element: R|kotlin/Any?|"];
subgraph cluster_23 { subgraph cluster_23 {
color=blue color=blue
68 [label="Enter when"]; 69 [label="Enter when"];
subgraph cluster_24 { subgraph cluster_24 {
color=blue color=blue
69 [label="Enter when branch condition "]; 70 [label="Enter when branch condition "];
70 [label="Access variable R|<local>/element|"]; 71 [label="Access variable R|<local>/element|"];
71 [label="Type operator: (R|<local>/element| is R|T|)"]; 72 [label="Type operator: (R|<local>/element| is R|T|)"];
72 [label="Exit when branch condition"]; 73 [label="Exit when branch condition"];
} }
73 [label="Synthetic else branch"]; 74 [label="Synthetic else branch"];
74 [label="Enter when branch result"]; 75 [label="Enter when branch result"];
subgraph cluster_25 { subgraph cluster_25 {
color=blue color=blue
75 [label="Enter block"]; 76 [label="Enter block"];
76 [label="Access variable R|<local>/element|"]; 77 [label="Access variable R|<local>/element|"];
77 [label="Smart cast: R|<local>/element|"]; 78 [label="Smart cast: R|<local>/element|"];
78 [label="Jump: ^firstIsInstanceOrNull R|<local>/element|"]; 79 [label="Jump: ^firstIsInstanceOrNull R|<local>/element|"];
79 [label="Stub" style="filled" fillcolor=gray]; 80 [label="Stub" style="filled" fillcolor=gray];
80 [label="Exit block" style="filled" fillcolor=gray]; 81 [label="Exit block" style="filled" fillcolor=gray];
} }
81 [label="Exit when branch result" style="filled" fillcolor=gray]; 82 [label="Exit when branch result" style="filled" fillcolor=gray];
82 [label="Exit when"]; 83 [label="Exit when"];
} }
83 [label="Exit block"]; 84 [label="Exit block"];
} }
84 [label="Exit loop block"]; 85 [label="Exit loop block"];
} }
85 [label="Exit whileloop"]; 86 [label="Exit whileloop"];
} }
86 [label="Exit block"]; 87 [label="Exit block"];
} }
87 [label="Const: Null(null)"]; 88 [label="Const: Null(null)"];
88 [label="Jump: ^firstIsInstanceOrNull Null(null)"]; 89 [label="Jump: ^firstIsInstanceOrNull Null(null)"];
89 [label="Stub" style="filled" fillcolor=gray]; 90 [label="Stub" style="filled" fillcolor=gray];
90 [label="Exit block" style="filled" fillcolor=gray]; 91 [label="Exit block" style="filled" fillcolor=gray];
} }
91 [label="Exit function firstIsInstanceOrNull" style="filled" fillcolor=red]; 92 [label="Exit function firstIsInstanceOrNull" style="filled" fillcolor=red];
} }
52 -> {53};
53 -> {54}; 53 -> {54};
54 -> {55}; 54 -> {55};
55 -> {56}; 55 -> {56};
@@ -253,8 +254,8 @@ digraph complex_kt {
59 -> {60}; 59 -> {60};
60 -> {61}; 60 -> {61};
61 -> {62}; 61 -> {62};
62 -> {85 63}; 62 -> {63};
63 -> {64}; 63 -> {86 64};
64 -> {65}; 64 -> {65};
65 -> {66}; 65 -> {66};
66 -> {67}; 66 -> {67};
@@ -263,26 +264,27 @@ digraph complex_kt {
69 -> {70}; 69 -> {70};
70 -> {71}; 70 -> {71};
71 -> {72}; 71 -> {72};
72 -> {74 73}; 72 -> {73};
73 -> {82}; 73 -> {75 74};
74 -> {75}; 74 -> {83};
75 -> {76}; 75 -> {76};
76 -> {77}; 76 -> {77};
77 -> {78}; 77 -> {78};
78 -> {91}; 78 -> {79};
78 -> {79} [style=dotted]; 79 -> {92};
79 -> {80} [style=dotted]; 79 -> {80} [style=dotted];
80 -> {81} [style=dotted]; 80 -> {81} [style=dotted];
81 -> {82} [style=dotted]; 81 -> {82} [style=dotted];
82 -> {83}; 82 -> {83} [style=dotted];
83 -> {84}; 83 -> {84};
84 -> {59} [color=green style=dashed]; 84 -> {85};
85 -> {86}; 85 -> {60} [color=green style=dashed];
86 -> {87}; 86 -> {87};
87 -> {88}; 87 -> {88};
88 -> {91}; 88 -> {89};
88 -> {89} [style=dotted]; 89 -> {92};
89 -> {90} [style=dotted]; 89 -> {90} [style=dotted];
90 -> {91} [style=dotted]; 90 -> {91} [style=dotted];
91 -> {92} [style=dotted];
} }
@@ -135,14 +135,14 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
44 [label="Postponed enter to lambda"]; 44 [label="Postponed enter to lambda"];
subgraph cluster_16 { subgraph cluster_16 {
color=blue color=blue
59 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; 60 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_17 { subgraph cluster_17 {
color=blue color=blue
60 [label="Enter block"]; 61 [label="Enter block"];
61 [label="Function call: R|/materialize|<R|kotlin/String|>()"]; 62 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
62 [label="Exit block"]; 63 [label="Exit block"];
} }
63 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; 64 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
} }
45 [label="Postponed exit from lambda"]; 45 [label="Postponed exit from lambda"];
46 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"]; 46 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"];
@@ -153,36 +153,37 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
subgraph cluster_18 { subgraph cluster_18 {
color=blue color=blue
49 [label="Catch enter"]; 49 [label="Catch enter"];
50 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_19 { subgraph cluster_19 {
color=blue color=blue
50 [label="Enter block"]; 51 [label="Enter block"];
51 [label="Const: String()"]; 52 [label="Const: String()"];
52 [label="Exit block"]; 53 [label="Exit block"];
} }
53 [label="Catch exit"]; 54 [label="Catch exit"];
} }
54 [label="Try expression exit"]; 55 [label="Try expression exit"];
} }
55 [label="Call arguments union" style="filled" fillcolor=yellow]; 56 [label="Call arguments union" style="filled" fillcolor=yellow];
56 [label="Variable declaration: lval x: R|kotlin/String|"]; 57 [label="Variable declaration: lval x: R|kotlin/String|"];
57 [label="Exit block"]; 58 [label="Exit block"];
} }
58 [label="Exit function test_2" style="filled" fillcolor=red]; 59 [label="Exit function test_2" style="filled" fillcolor=red];
} }
39 -> {40}; 39 -> {40};
40 -> {41}; 40 -> {41};
41 -> {42 49}; 41 -> {42 49};
42 -> {43}; 42 -> {43};
43 -> {44}; 43 -> {44};
44 -> {59}; 44 -> {60};
44 -> {45} [color=red]; 44 -> {45} [color=red];
44 -> {59} [style=dashed]; 44 -> {60} [style=dashed];
45 -> {46}; 45 -> {46};
46 -> {47}; 46 -> {47};
47 -> {48}; 47 -> {48};
48 -> {54 49}; 48 -> {55 49};
49 -> {50}; 49 -> {50};
49 -> {58} [label=onUncaughtException]; 49 -> {59} [label=onUncaughtException];
50 -> {51}; 50 -> {51};
51 -> {52}; 51 -> {52};
52 -> {53}; 52 -> {53};
@@ -191,56 +192,57 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
55 -> {56}; 55 -> {56};
56 -> {57}; 56 -> {57};
57 -> {58}; 57 -> {58};
59 -> {60}; 58 -> {59};
60 -> {61}; 60 -> {61};
61 -> {62}; 61 -> {62};
62 -> {63}; 62 -> {63};
63 -> {55} [color=red]; 63 -> {64};
63 -> {45} [color=green]; 64 -> {56} [color=red];
64 -> {45} [color=green];
subgraph cluster_20 { subgraph cluster_20 {
color=red color=red
64 [label="Enter function test_3" style="filled" fillcolor=red]; 65 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_21 { subgraph cluster_21 {
color=blue color=blue
65 [label="Enter block"]; 66 [label="Enter block"];
66 [label="Postponed enter to lambda"]; 67 [label="Postponed enter to lambda"];
subgraph cluster_22 { subgraph cluster_22 {
color=blue color=blue
74 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; 75 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_23 { subgraph cluster_23 {
color=blue color=blue
75 [label="Enter block"]; 76 [label="Enter block"];
76 [label="Function call: R|/materialize|<R|kotlin/String?|>()"]; 77 [label="Function call: R|/materialize|<R|kotlin/String?|>()"];
77 [label="Exit block"]; 78 [label="Exit block"];
} }
78 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; 79 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
} }
67 [label="Postponed exit from lambda"]; 68 [label="Postponed exit from lambda"];
68 [label="Function call: R|kotlin/run|<R|kotlin/String?|>(...)"]; 69 [label="Function call: R|kotlin/run|<R|kotlin/String?|>(...)"];
69 [label="Check not null: R|kotlin/run|<R|kotlin/String?|>(...)!!"]; 70 [label="Check not null: R|kotlin/run|<R|kotlin/String?|>(...)!!"];
70 [label="Call arguments union" style="filled" fillcolor=yellow]; 71 [label="Call arguments union" style="filled" fillcolor=yellow];
71 [label="Variable declaration: lval x: R|kotlin/String|"]; 72 [label="Variable declaration: lval x: R|kotlin/String|"];
72 [label="Exit block"]; 73 [label="Exit block"];
} }
73 [label="Exit function test_3" style="filled" fillcolor=red]; 74 [label="Exit function test_3" style="filled" fillcolor=red];
} }
64 -> {65};
65 -> {66}; 65 -> {66};
66 -> {74}; 66 -> {67};
66 -> {67} [color=red]; 67 -> {75};
66 -> {74} [style=dashed]; 67 -> {68} [color=red];
67 -> {68}; 67 -> {75} [style=dashed];
68 -> {69}; 68 -> {69};
69 -> {70}; 69 -> {70};
70 -> {71}; 70 -> {71};
71 -> {72}; 71 -> {72};
72 -> {73}; 72 -> {73};
74 -> {75}; 73 -> {74};
75 -> {76}; 75 -> {76};
76 -> {77}; 76 -> {77};
77 -> {78}; 77 -> {78};
78 -> {70} [color=red]; 78 -> {79};
78 -> {67} [color=green]; 79 -> {71} [color=red];
79 -> {68} [color=green];
} }
@@ -269,39 +269,40 @@ digraph propertiesAndInitBlocks_kt {
subgraph cluster_27 { subgraph cluster_27 {
color=blue color=blue
87 [label="Catch enter"]; 87 [label="Catch enter"];
88 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_28 { subgraph cluster_28 {
color=blue color=blue
88 [label="Enter block"]; 89 [label="Enter block"];
89 [label="Const: Int(2)"]; 90 [label="Const: Int(2)"];
90 [label="Exit block"]; 91 [label="Exit block"];
} }
91 [label="Catch exit"]; 92 [label="Catch exit"];
} }
subgraph cluster_29 { subgraph cluster_29 {
color=blue color=blue
92 [label="Enter finally"]; 93 [label="Enter finally"];
subgraph cluster_30 { subgraph cluster_30 {
color=blue color=blue
93 [label="Enter block"]; 94 [label="Enter block"];
94 [label="Const: Int(0)"]; 95 [label="Const: Int(0)"];
95 [label="Exit block"]; 96 [label="Exit block"];
} }
96 [label="Exit finally"]; 97 [label="Exit finally"];
} }
97 [label="Try expression exit"]; 98 [label="Try expression exit"];
} }
98 [label="Exit property" style="filled" fillcolor=red]; 99 [label="Exit property" style="filled" fillcolor=red];
} }
80 -> {81}; 80 -> {81};
81 -> {82 87}; 81 -> {82 87};
81 -> {92} [label=onUncaughtException]; 81 -> {93} [label=onUncaughtException];
82 -> {83}; 82 -> {83};
83 -> {84}; 83 -> {84};
84 -> {85}; 84 -> {85};
85 -> {86}; 85 -> {86};
86 -> {92 87}; 86 -> {93 87};
87 -> {88}; 87 -> {88};
87 -> {92} [label=onUncaughtException]; 87 -> {93} [label=onUncaughtException];
88 -> {89}; 88 -> {89};
89 -> {90}; 89 -> {90};
90 -> {91}; 90 -> {91};
@@ -311,7 +312,8 @@ digraph propertiesAndInitBlocks_kt {
94 -> {95}; 94 -> {95};
95 -> {96}; 95 -> {96};
96 -> {97}; 96 -> {97};
96 -> {98} [label=onUncaughtException];
97 -> {98}; 97 -> {98};
97 -> {99} [label=onUncaughtException];
98 -> {99};
} }
+162 -152
View File
@@ -27,301 +27,311 @@ digraph tryCatch_kt {
subgraph cluster_5 { subgraph cluster_5 {
color=blue color=blue
9 [label="Catch enter"]; 9 [label="Catch enter"];
10 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_6 { subgraph cluster_6 {
color=blue color=blue
10 [label="Enter block"]; 11 [label="Enter block"];
11 [label="Const: Int(3)"]; 12 [label="Const: Int(3)"];
12 [label="Variable declaration: lval z: R|kotlin/Int|"]; 13 [label="Variable declaration: lval z: R|kotlin/Int|"];
13 [label="Exit block"]; 14 [label="Exit block"];
} }
14 [label="Catch exit"]; 15 [label="Catch exit"];
} }
subgraph cluster_7 { subgraph cluster_7 {
color=blue color=blue
15 [label="Catch enter"]; 16 [label="Catch enter"];
17 [label="Variable declaration: e: R|kotlin/RuntimeException|"];
subgraph cluster_8 { subgraph cluster_8 {
color=blue color=blue
16 [label="Enter block"]; 18 [label="Enter block"];
17 [label="Const: Int(2)"]; 19 [label="Const: Int(2)"];
18 [label="Variable declaration: lval y: R|kotlin/Int|"]; 20 [label="Variable declaration: lval y: R|kotlin/Int|"];
19 [label="Exit block"]; 21 [label="Exit block"];
} }
20 [label="Catch exit"]; 22 [label="Catch exit"];
} }
21 [label="Try expression exit"]; 23 [label="Try expression exit"];
} }
22 [label="Exit block"]; 24 [label="Exit block"];
} }
23 [label="Exit function test_1" style="filled" fillcolor=red]; 25 [label="Exit function test_1" style="filled" fillcolor=red];
} }
0 -> {1}; 0 -> {1};
1 -> {2}; 1 -> {2};
2 -> {3 15 9}; 2 -> {3 16 9};
3 -> {4}; 3 -> {4};
4 -> {5}; 4 -> {5};
5 -> {6}; 5 -> {6};
6 -> {7}; 6 -> {7};
7 -> {8}; 7 -> {8};
8 -> {21 15 9}; 8 -> {23 16 9};
9 -> {10}; 9 -> {10};
9 -> {23} [label=onUncaughtException]; 9 -> {25} [label=onUncaughtException];
10 -> {11}; 10 -> {11};
11 -> {12}; 11 -> {12};
12 -> {13}; 12 -> {13};
13 -> {14}; 13 -> {14};
14 -> {21}; 14 -> {15};
15 -> {16}; 15 -> {23};
15 -> {23} [label=onUncaughtException];
16 -> {17}; 16 -> {17};
16 -> {25} [label=onUncaughtException];
17 -> {18}; 17 -> {18};
18 -> {19}; 18 -> {19};
19 -> {20}; 19 -> {20};
20 -> {21}; 20 -> {21};
21 -> {22}; 21 -> {22};
22 -> {23}; 22 -> {23};
23 -> {24};
24 -> {25};
subgraph cluster_9 { subgraph cluster_9 {
color=red color=red
24 [label="Enter function test_2" style="filled" fillcolor=red]; 26 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_10 { subgraph cluster_10 {
color=blue color=blue
25 [label="Enter block"]; 27 [label="Enter block"];
subgraph cluster_11 { subgraph cluster_11 {
color=blue color=blue
26 [label="Try expression enter"]; 28 [label="Try expression enter"];
subgraph cluster_12 { subgraph cluster_12 {
color=blue color=blue
27 [label="Try main block enter"]; 29 [label="Try main block enter"];
subgraph cluster_13 { subgraph cluster_13 {
color=blue color=blue
28 [label="Enter block"]; 30 [label="Enter block"];
29 [label="Const: Int(1)"]; 31 [label="Const: Int(1)"];
30 [label="Exit block"]; 32 [label="Exit block"];
} }
31 [label="Try main block exit"]; 33 [label="Try main block exit"];
} }
subgraph cluster_14 { subgraph cluster_14 {
color=blue color=blue
32 [label="Catch enter"]; 34 [label="Catch enter"];
35 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_15 { subgraph cluster_15 {
color=blue color=blue
33 [label="Enter block"]; 36 [label="Enter block"];
34 [label="Const: Int(2)"]; 37 [label="Const: Int(2)"];
35 [label="Exit block"]; 38 [label="Exit block"];
} }
36 [label="Catch exit"]; 39 [label="Catch exit"];
} }
37 [label="Try expression exit"]; 40 [label="Try expression exit"];
} }
38 [label="Variable declaration: lval x: R|kotlin/Int|"]; 41 [label="Variable declaration: lval x: R|kotlin/Int|"];
39 [label="Exit block"]; 42 [label="Exit block"];
} }
40 [label="Exit function test_2" style="filled" fillcolor=red]; 43 [label="Exit function test_2" style="filled" fillcolor=red];
} }
24 -> {25}; 26 -> {27};
25 -> {26};
26 -> {27 32};
27 -> {28}; 27 -> {28};
28 -> {29}; 28 -> {29 34};
29 -> {30}; 29 -> {30};
30 -> {31}; 30 -> {31};
31 -> {37 32}; 31 -> {32};
32 -> {33}; 32 -> {33};
32 -> {40} [label=onUncaughtException]; 33 -> {40 34};
33 -> {34};
34 -> {35}; 34 -> {35};
34 -> {43} [label=onUncaughtException];
35 -> {36}; 35 -> {36};
36 -> {37}; 36 -> {37};
37 -> {38}; 37 -> {38};
38 -> {39}; 38 -> {39};
39 -> {40}; 39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
subgraph cluster_16 { subgraph cluster_16 {
color=red color=red
41 [label="Enter function test_3" style="filled" fillcolor=red]; 44 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_17 { subgraph cluster_17 {
color=blue color=blue
42 [label="Enter block"]; 45 [label="Enter block"];
subgraph cluster_18 { subgraph cluster_18 {
color=blue color=blue
43 [label="Enter while loop"]; 46 [label="Enter while loop"];
subgraph cluster_19 { subgraph cluster_19 {
color=blue color=blue
44 [label="Enter loop condition"]; 47 [label="Enter loop condition"];
45 [label="Const: Boolean(true)"]; 48 [label="Const: Boolean(true)"];
46 [label="Exit loop condition"]; 49 [label="Exit loop condition"];
} }
subgraph cluster_20 { subgraph cluster_20 {
color=blue color=blue
47 [label="Enter loop block"]; 50 [label="Enter loop block"];
subgraph cluster_21 { subgraph cluster_21 {
color=blue color=blue
48 [label="Enter block"]; 51 [label="Enter block"];
subgraph cluster_22 { subgraph cluster_22 {
color=blue color=blue
49 [label="Try expression enter"]; 52 [label="Try expression enter"];
subgraph cluster_23 { subgraph cluster_23 {
color=blue color=blue
50 [label="Try main block enter"]; 53 [label="Try main block enter"];
subgraph cluster_24 { subgraph cluster_24 {
color=blue color=blue
51 [label="Enter block"]; 54 [label="Enter block"];
subgraph cluster_25 { subgraph cluster_25 {
color=blue color=blue
52 [label="Enter when"]; 55 [label="Enter when"];
subgraph cluster_26 { subgraph cluster_26 {
color=blue color=blue
53 [label="Enter when branch condition "]; 56 [label="Enter when branch condition "];
54 [label="Access variable R|<local>/b|"]; 57 [label="Access variable R|<local>/b|"];
55 [label="Exit when branch condition"]; 58 [label="Exit when branch condition"];
} }
56 [label="Synthetic else branch"]; 59 [label="Synthetic else branch"];
57 [label="Enter when branch result"]; 60 [label="Enter when branch result"];
subgraph cluster_27 { subgraph cluster_27 {
color=blue color=blue
58 [label="Enter block"]; 61 [label="Enter block"];
59 [label="Jump: ^test_3 Unit"]; 62 [label="Jump: ^test_3 Unit"];
60 [label="Stub" style="filled" fillcolor=gray]; 63 [label="Stub" style="filled" fillcolor=gray];
61 [label="Exit block" style="filled" fillcolor=gray]; 64 [label="Exit block" style="filled" fillcolor=gray];
} }
62 [label="Exit when branch result" style="filled" fillcolor=gray]; 65 [label="Exit when branch result" style="filled" fillcolor=gray];
63 [label="Exit when"]; 66 [label="Exit when"];
} }
64 [label="Const: Int(1)"]; 67 [label="Const: Int(1)"];
65 [label="Variable declaration: lval x: R|kotlin/Int|"]; 68 [label="Variable declaration: lval x: R|kotlin/Int|"];
subgraph cluster_28 { subgraph cluster_28 {
color=blue color=blue
66 [label="Enter when"]; 69 [label="Enter when"];
subgraph cluster_29 { subgraph cluster_29 {
color=blue color=blue
67 [label="Enter when branch condition "]; 70 [label="Enter when branch condition "];
68 [label="Access variable R|<local>/b|"]; 71 [label="Access variable R|<local>/b|"];
69 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()"]; 72 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()"];
70 [label="Exit when branch condition"]; 73 [label="Exit when branch condition"];
} }
71 [label="Synthetic else branch"]; 74 [label="Synthetic else branch"];
72 [label="Enter when branch result"]; 75 [label="Enter when branch result"];
subgraph cluster_30 { subgraph cluster_30 {
color=blue color=blue
73 [label="Enter block"]; 76 [label="Enter block"];
74 [label="Jump: break@@@[Boolean(true)] "]; 77 [label="Jump: break@@@[Boolean(true)] "];
75 [label="Stub" style="filled" fillcolor=gray]; 78 [label="Stub" style="filled" fillcolor=gray];
76 [label="Exit block" style="filled" fillcolor=gray]; 79 [label="Exit block" style="filled" fillcolor=gray];
} }
77 [label="Exit when branch result" style="filled" fillcolor=gray]; 80 [label="Exit when branch result" style="filled" fillcolor=gray];
78 [label="Exit when"]; 81 [label="Exit when"];
} }
79 [label="Exit block"]; 82 [label="Exit block"];
} }
80 [label="Try main block exit"]; 83 [label="Try main block exit"];
} }
subgraph cluster_31 { subgraph cluster_31 {
color=blue color=blue
81 [label="Catch enter"]; 84 [label="Catch enter"];
85 [label="Variable declaration: e: R|kotlin/RuntimeException|"];
subgraph cluster_32 { subgraph cluster_32 {
color=blue color=blue
82 [label="Enter block"]; 86 [label="Enter block"];
83 [label="Jump: break@@@[Boolean(true)] "]; 87 [label="Jump: break@@@[Boolean(true)] "];
84 [label="Stub" style="filled" fillcolor=gray]; 88 [label="Stub" style="filled" fillcolor=gray];
85 [label="Exit block" style="filled" fillcolor=gray]; 89 [label="Exit block" style="filled" fillcolor=gray];
} }
86 [label="Catch exit" style="filled" fillcolor=gray]; 90 [label="Catch exit" style="filled" fillcolor=gray];
} }
subgraph cluster_33 { subgraph cluster_33 {
color=blue color=blue
91 [label="Catch enter"]; 95 [label="Catch enter"];
96 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_34 { subgraph cluster_34 {
color=blue color=blue
92 [label="Enter block"]; 97 [label="Enter block"];
93 [label="Jump: continue@@@[Boolean(true)] "]; 98 [label="Jump: continue@@@[Boolean(true)] "];
94 [label="Stub" style="filled" fillcolor=gray]; 99 [label="Stub" style="filled" fillcolor=gray];
95 [label="Exit block" style="filled" fillcolor=gray]; 100 [label="Exit block" style="filled" fillcolor=gray];
} }
96 [label="Catch exit" style="filled" fillcolor=gray]; 101 [label="Catch exit" style="filled" fillcolor=gray];
} }
97 [label="Try expression exit"]; 102 [label="Try expression exit"];
} }
98 [label="Const: Int(2)"]; 103 [label="Const: Int(2)"];
99 [label="Variable declaration: lval y: R|kotlin/Int|"]; 104 [label="Variable declaration: lval y: R|kotlin/Int|"];
100 [label="Exit block"]; 105 [label="Exit block"];
} }
101 [label="Exit loop block"]; 106 [label="Exit loop block"];
} }
87 [label="Exit whileloop"]; 91 [label="Exit whileloop"];
} }
88 [label="Const: Int(3)"]; 92 [label="Const: Int(3)"];
89 [label="Variable declaration: lval z: R|kotlin/Int|"]; 93 [label="Variable declaration: lval z: R|kotlin/Int|"];
90 [label="Exit block"]; 94 [label="Exit block"];
} }
102 [label="Exit function test_3" style="filled" fillcolor=red]; 107 [label="Exit function test_3" style="filled" fillcolor=red];
} }
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45}; 44 -> {45};
45 -> {46}; 45 -> {46};
46 -> {47}; 46 -> {47};
46 -> {87} [style=dotted];
47 -> {48}; 47 -> {48};
48 -> {49}; 48 -> {49};
49 -> {50 91 81}; 49 -> {50};
49 -> {91} [style=dotted];
50 -> {51}; 50 -> {51};
51 -> {52}; 51 -> {52};
52 -> {53}; 52 -> {53 95 84};
53 -> {54}; 53 -> {54};
54 -> {55}; 54 -> {55};
55 -> {57 56}; 55 -> {56};
56 -> {63}; 56 -> {57};
57 -> {58}; 57 -> {58};
58 -> {59}; 58 -> {60 59};
59 -> {102}; 59 -> {66};
59 -> {60} [style=dotted]; 60 -> {61};
60 -> {61} [style=dotted]; 61 -> {62};
61 -> {62} [style=dotted]; 62 -> {107};
62 -> {63} [style=dotted]; 62 -> {63} [style=dotted];
63 -> {64}; 63 -> {64} [style=dotted];
64 -> {65}; 64 -> {65} [style=dotted];
65 -> {66}; 65 -> {66} [style=dotted];
66 -> {67}; 66 -> {67};
67 -> {68}; 67 -> {68};
68 -> {69}; 68 -> {69};
69 -> {70}; 69 -> {70};
70 -> {72 71}; 70 -> {71};
71 -> {78}; 71 -> {72};
72 -> {73}; 72 -> {73};
73 -> {74}; 73 -> {75 74};
74 -> {87}; 74 -> {81};
74 -> {75} [style=dotted]; 75 -> {76};
75 -> {76} [style=dotted]; 76 -> {77};
76 -> {77} [style=dotted]; 77 -> {91};
77 -> {78} [style=dotted]; 77 -> {78} [style=dotted];
78 -> {79}; 78 -> {79} [style=dotted];
79 -> {80}; 79 -> {80} [style=dotted];
80 -> {97 91 81}; 80 -> {81} [style=dotted];
81 -> {82}; 81 -> {82};
81 -> {102} [label=onUncaughtException];
82 -> {83}; 82 -> {83};
83 -> {87}; 83 -> {102 95 84};
83 -> {84} [style=dotted]; 84 -> {85};
84 -> {85} [style=dotted]; 84 -> {107} [label=onUncaughtException];
85 -> {86} [style=dotted]; 85 -> {86};
86 -> {97} [style=dotted]; 86 -> {87};
87 -> {88}; 87 -> {91};
88 -> {89}; 87 -> {88} [style=dotted];
89 -> {90}; 88 -> {89} [style=dotted];
90 -> {102}; 89 -> {90} [style=dotted];
90 -> {102} [style=dotted];
91 -> {92}; 91 -> {92};
91 -> {102} [label=onUncaughtException];
92 -> {93}; 92 -> {93};
93 -> {94} [style=dotted]; 93 -> {94};
93 -> {43} [color=green style=dashed]; 94 -> {107};
94 -> {95} [style=dotted]; 95 -> {96};
95 -> {96} [style=dotted]; 95 -> {107} [label=onUncaughtException];
96 -> {97} [style=dotted]; 96 -> {97};
97 -> {98}; 97 -> {98};
98 -> {99}; 98 -> {99} [style=dotted];
99 -> {100}; 98 -> {46} [color=green style=dashed];
100 -> {101}; 99 -> {100} [style=dotted];
101 -> {44} [color=green style=dashed]; 100 -> {101} [style=dotted];
101 -> {102} [style=dotted];
102 -> {103};
103 -> {104};
104 -> {105};
105 -> {106};
106 -> {47} [color=green style=dashed];
} }
@@ -8,18 +8,19 @@ package org.jetbrains.kotlin.fir.analysis.cfa
import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange
import org.jetbrains.kotlin.contracts.description.canBeRevisited import org.jetbrains.kotlin.contracts.description.canBeRevisited
import org.jetbrains.kotlin.contracts.description.isDefinitelyVisited import org.jetbrains.kotlin.contracts.description.isDefinitelyVisited
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.analysis.cfa.util.PathAwarePropertyInitializationInfo import org.jetbrains.kotlin.fir.analysis.cfa.util.PathAwarePropertyInitializationInfo
import org.jetbrains.kotlin.fir.analysis.cfa.util.PropertyInitializationInfo import org.jetbrains.kotlin.fir.analysis.cfa.util.PropertyInitializationInfo
import org.jetbrains.kotlin.fir.analysis.cfa.util.TraverseDirection import org.jetbrains.kotlin.fir.analysis.cfa.util.TraverseDirection
import org.jetbrains.kotlin.fir.analysis.cfa.util.traverse import org.jetbrains.kotlin.fir.analysis.cfa.util.traverse
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.utils.isLateInit import org.jetbrains.kotlin.fir.declarations.utils.isLateInit
import org.jetbrains.kotlin.fir.declarations.utils.referredPropertySymbol import org.jetbrains.kotlin.fir.declarations.utils.referredPropertySymbol
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
import org.jetbrains.kotlin.fir.isCatchParameter
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.* import org.jetbrains.kotlin.fir.resolve.dfa.cfg.*
import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
@@ -37,16 +38,22 @@ object FirPropertyInitializationAnalyzer : AbstractFirPropertyInitializationChec
context: CheckerContext context: CheckerContext
) { ) {
val localData = data.filter { val localData = data.filter {
val symbolFir = (it.key.fir as? FirVariableSymbol<*>)?.fir val symbol = it.key.fir as? FirVariableSymbol<*>
symbolFir == null || symbolFir.initializer == null && symbolFir.delegate == null symbol == null || !symbol.isInitialized()
} }
val localProperties = properties.filterTo(mutableSetOf()) { it.fir.initializer == null && it.fir.delegate == null } val localProperties = properties.filterNotTo(mutableSetOf()) { it.isInitialized() }
val reporterVisitor = PropertyReporter(localData, localProperties, capturedWrites, reporter, context) val reporterVisitor = PropertyReporter(localData, localProperties, capturedWrites, reporter, context)
graph.traverse(TraverseDirection.Forward, reporterVisitor) graph.traverse(TraverseDirection.Forward, reporterVisitor)
} }
private fun FirVariableSymbol<*>.isInitialized(): Boolean {
return fir.initializer != null
|| fir.delegate != null
|| this is FirPropertySymbol && fir.isCatchParameter == true
}
private class PropertyReporter( private class PropertyReporter(
val data: Map<CFGNode<*>, PathAwarePropertyInitializationInfo>, val data: Map<CFGNode<*>, PathAwarePropertyInitializationInfo>,
val localProperties: Set<FirPropertySymbol>, val localProperties: Set<FirPropertySymbol>,
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.isUnderscore import org.jetbrains.kotlin.fir.analysis.checkers.isUnderscore
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.isCatchParameter
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.FirUserTypeRef
@@ -22,7 +23,7 @@ object FirReservedUnderscoreDeclarationChecker : FirBasicDeclarationChecker() {
if ( if (
declaration is FirRegularClass || declaration is FirRegularClass ||
declaration is FirTypeParameter || declaration is FirTypeParameter ||
declaration is FirProperty || declaration is FirProperty && declaration.isCatchParameter != true ||
declaration is FirTypeAlias declaration is FirTypeAlias
) { ) {
reportIfUnderscore(declaration, context, reporter) reportIfUnderscore(declaration, context, reporter)
@@ -5,12 +5,13 @@
package org.jetbrains.kotlin.fir.analysis.checkers.expression package org.jetbrains.kotlin.fir.analysis.checkers.expression
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.defaultValueForParameter
import org.jetbrains.kotlin.fir.analysis.checkers.isSubtypeOfThrowable import org.jetbrains.kotlin.fir.analysis.checkers.isSubtypeOfThrowable
import org.jetbrains.kotlin.fir.analysis.checkers.valOrVarKeyword import org.jetbrains.kotlin.fir.analysis.checkers.valOrVarKeyword
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.expressions.FirTryExpression import org.jetbrains.kotlin.fir.expressions.FirTryExpression
import org.jetbrains.kotlin.fir.types.ConeTypeParameterType import org.jetbrains.kotlin.fir.types.ConeTypeParameterType
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
@@ -23,7 +24,7 @@ object FirCatchParameterChecker : FirTryExpressionChecker() {
val catchParameter = catchEntry.parameter val catchParameter = catchEntry.parameter
val source = catchParameter.source ?: continue val source = catchParameter.source ?: continue
if (catchParameter.defaultValue != null) { if (catchParameter.source?.defaultValueForParameter != null) {
reporter.reportOn(source, FirErrors.CATCH_PARAMETER_WITH_DEFAULT_VALUE, context) reporter.reportOn(source, FirErrors.CATCH_PARAMETER_WITH_DEFAULT_VALUE, context)
} }
@@ -9,16 +9,15 @@ import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf import kotlinx.collections.immutable.persistentMapOf
import org.jetbrains.kotlin.KtFakeSourceElementKind import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.fir.FirAnnotationContainer import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.analysis.cfa.util.* import org.jetbrains.kotlin.fir.analysis.cfa.util.*
import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol
import org.jetbrains.kotlin.fir.analysis.checkers.isIterator import org.jetbrains.kotlin.fir.analysis.checkers.isIterator
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.declarations.utils.isLocal
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirAnnotation
@@ -26,14 +25,12 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.* import org.jetbrains.kotlin.fir.resolve.dfa.cfg.*
import org.jetbrains.kotlin.fir.resolved
import org.jetbrains.kotlin.fir.resolvedSymbol
import org.jetbrains.kotlin.fir.types.isFunctionalType
import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.isFunctionalType
object UnusedChecker : FirControlFlowChecker() { object UnusedChecker : FirControlFlowChecker() {
override fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, context: CheckerContext) { override fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, context: CheckerContext) {
@@ -81,9 +78,13 @@ object UnusedChecker : FirControlFlowChecker() {
val variableSource = variable.source.takeIf { it?.elementType != KtNodeTypes.DESTRUCTURING_DECLARATION } val variableSource = variable.source.takeIf { it?.elementType != KtNodeTypes.DESTRUCTURING_DECLARATION }
when { when {
data == VariableStatus.UNUSED -> { data == VariableStatus.UNUSED -> {
if ((node.fir.initializer as? FirFunctionCall)?.isIterator != true) { when {
reporter.reportOn(variableSource, FirErrors.UNUSED_VARIABLE, context) (node.fir.initializer as? FirFunctionCall)?.isIterator == true -> {}
break node.fir.isCatchParameter == true -> {}
else -> {
reporter.reportOn(variableSource, FirErrors.UNUSED_VARIABLE, context)
break
}
} }
} }
data.isRedundantInit -> { data.isRedundantInit -> {
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.KtLightSourceElement import org.jetbrains.kotlin.KtLightSourceElement
import org.jetbrains.kotlin.KtNodeTypes.* import org.jetbrains.kotlin.KtNodeTypes.*
import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fakeElement import org.jetbrains.kotlin.fakeElement
@@ -25,6 +26,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildAnonymousFunction
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
import org.jetbrains.kotlin.fir.diagnostics.* import org.jetbrains.kotlin.fir.diagnostics.*
import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.* import org.jetbrains.kotlin.fir.expressions.builder.*
@@ -44,6 +46,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
import org.jetbrains.kotlin.fir.types.FirTypeProjection import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
import org.jetbrains.kotlin.psi.stubs.elements.KtNameReferenceExpressionElementType import org.jetbrains.kotlin.psi.stubs.elements.KtNameReferenceExpressionElementType
@@ -1198,7 +1201,20 @@ class ExpressionsConverter(
for ((parameter, block) in catchClauses) { for ((parameter, block) in catchClauses) {
if (parameter == null) continue if (parameter == null) continue
catches += buildCatch { catches += buildCatch {
this.parameter = parameter.firValueParameter this.parameter = buildProperty {
source = parameter.source
moduleData = baseModuleData
origin = FirDeclarationOrigin.Source
returnTypeRef = parameter.returnTypeRef
isVar = false
status = FirResolvedDeclarationStatusImpl(Visibilities.Local, Modality.FINAL, EffectiveVisibility.Local)
isLocal = true
this.name = parameter.name
symbol = FirPropertySymbol(CallableId(name))
annotations += parameter.annotations
}.also {
it.isCatchParameter = true
}
this.block = block this.block = block
} }
} }
@@ -48,7 +48,7 @@ class ValueParameter(
private val isVar: Boolean, private val isVar: Boolean,
private val modifiers: Modifier, private val modifiers: Modifier,
val returnTypeRef: FirTypeRef, val returnTypeRef: FirTypeRef,
private val source: KtSourceElement, val source: KtSourceElement,
private val moduleData: FirModuleData, private val moduleData: FirModuleData,
private val isFromPrimaryConstructor: Boolean, private val isFromPrimaryConstructor: Boolean,
private val additionalAnnotations: List<FirAnnotation>, private val additionalAnnotations: List<FirAnnotation>,
@@ -60,6 +60,19 @@ class ValueParameter(
return isVal || isVar return isVal || isVar
} }
val annotations: List<FirAnnotation> by lazy(LazyThreadSafetyMode.NONE) {
buildList {
if (!isFromPrimaryConstructor)
addAll(modifiers.annotations)
else
modifiers.annotations.filterTo(this) {
val useSiteTarget = it.useSiteTarget
useSiteTarget == null || useSiteTarget == AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER || useSiteTarget == AnnotationUseSiteTarget.RECEIVER || useSiteTarget == AnnotationUseSiteTarget.FILE
}
addAll(additionalAnnotations)
}
}
val firValueParameter: FirValueParameter by lazy(LazyThreadSafetyMode.NONE) { val firValueParameter: FirValueParameter by lazy(LazyThreadSafetyMode.NONE) {
buildValueParameter { buildValueParameter {
source = this@ValueParameter.source source = this@ValueParameter.source
@@ -72,13 +85,7 @@ class ValueParameter(
isCrossinline = modifiers.hasCrossinline() isCrossinline = modifiers.hasCrossinline()
isNoinline = modifiers.hasNoinline() isNoinline = modifiers.hasNoinline()
isVararg = modifiers.hasVararg() isVararg = modifiers.hasVararg()
annotations += if (!isFromPrimaryConstructor) annotations += this@ValueParameter.annotations
modifiers.annotations
else
modifiers.annotations.filter {
val useSiteTarget = it.useSiteTarget
useSiteTarget == null || useSiteTarget == AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER || useSiteTarget == AnnotationUseSiteTarget.RECEIVER || useSiteTarget == AnnotationUseSiteTarget.FILE
}
annotations += additionalAnnotations annotations += additionalAnnotations
} }
} }
@@ -11,10 +11,7 @@ import com.intellij.util.AstLoadingFilter
import org.jetbrains.kotlin.* import org.jetbrains.kotlin.*
import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.StandardNames.BACKING_FIELD import org.jetbrains.kotlin.builtins.StandardNames.BACKING_FIELD
import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.* import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.*
import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.contracts.FirContractDescription import org.jetbrains.kotlin.fir.contracts.FirContractDescription
@@ -1985,11 +1982,32 @@ open class RawFirBuilder(
tryBlock = expression.tryBlock.toFirBlock() tryBlock = expression.tryBlock.toFirBlock()
finallyBlock = expression.finallyBlock?.finalExpression?.toFirBlock() finallyBlock = expression.finallyBlock?.finalExpression?.toFirBlock()
for (clause in expression.catchClauses) { for (clause in expression.catchClauses) {
val parameter = clause.catchParameter?.let { val parameter = clause.catchParameter?.let { ktParameter ->
convertValueParameter( val name = convertValueParameterName(
it, ktParameter.nameAsSafeName,
valueParameterDeclaration = ValueParameterDeclaration.CATCH ktParameter.nameIdentifier?.node?.text,
ValueParameterDeclaration.CATCH
) )
buildProperty {
source = ktParameter.toFirSourceElement()
moduleData = baseModuleData
origin = FirDeclarationOrigin.Source
returnTypeRef = when {
ktParameter.typeReference != null -> ktParameter.typeReference.toFirOrErrorType()
else -> createNoTypeForParameterTypeRef()
}
isVar = false
status = FirResolvedDeclarationStatusImpl(Visibilities.Local, Modality.FINAL, EffectiveVisibility.Local)
isLocal = true
this.name = name
symbol = FirPropertySymbol(CallableId(name))
for (annotationEntry in ktParameter.annotationEntries) {
this.annotations += annotationEntry.convert<FirAnnotation>()
}
}.also {
it.isCatchParameter = true
}
} ?: continue } ?: continue
catches += buildCatch { catches += buildCatch {
source = clause.toFirSourceElement() source = clause.toFirSourceElement()
@@ -2,7 +2,7 @@ FILE: noParameterTypRefInCatch.kt
public? final? fun foo(): R|kotlin/Unit| { public? final? fun foo(): R|kotlin/Unit| {
try { try {
} }
catch (e: <ERROR TYPE REF: No type for parameter>) { catch ([IsCatchParameterProperty=true] e: <ERROR TYPE REF: No type for parameter>) {
} }
} }
@@ -3,10 +3,10 @@ FILE: try.kt
try { try {
throw KotlinNullPointerException#() throw KotlinNullPointerException#()
} }
catch (e: RuntimeException) { catch ([IsCatchParameterProperty=true] e: RuntimeException) {
println#(String(Runtime exception)) println#(String(Runtime exception))
} }
catch (e: Exception) { catch ([IsCatchParameterProperty=true] e: Exception) {
println#(String(Some exception)) println#(String(Some exception))
} }
finally { finally {
@@ -9,15 +9,18 @@ import com.intellij.testFramework.TestDataPath
import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub
import org.jetbrains.kotlin.fir.isCatchParameter
import org.jetbrains.kotlin.fir.psi import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.renderer.FirRenderer import org.jetbrains.kotlin.fir.renderer.FirRenderer
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -67,18 +70,18 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() {
} }
totalLength += FirRenderer().renderElementAsString(firFile).length totalLength += FirRenderer().renderElementAsString(firFile).length
counter++ counter++
firFile.accept(object : FirVisitorVoid() { firFile.accept(object : FirVisitor<Unit, FirElement>() {
override fun visitElement(element: FirElement) { override fun visitElement(element: FirElement, data: FirElement) {
element.acceptChildren(this) element.acceptChildren(this, element)
} }
override fun visitErrorExpression(errorExpression: FirErrorExpression) { override fun visitErrorExpression(errorExpression: FirErrorExpression, data: FirElement) {
errorExpressions++ errorExpressions++
println(errorExpression.render()) println(errorExpression.render())
errorExpression.psi?.let { println(it) } errorExpression.psi?.let { println(it) }
} }
override fun visitQualifiedAccess(qualifiedAccess: FirQualifiedAccess) { override fun visitQualifiedAccess(qualifiedAccess: FirQualifiedAccess, data: FirElement) {
val calleeReference = qualifiedAccess.calleeReference val calleeReference = qualifiedAccess.calleeReference
if (calleeReference is FirErrorNamedReference) { if (calleeReference is FirErrorNamedReference) {
errorReferences++ errorReferences++
@@ -86,23 +89,25 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() {
} else { } else {
normalReferences++ normalReferences++
} }
visitStatement(qualifiedAccess) visitStatement(qualifiedAccess, data)
} }
override fun visitExpression(expression: FirExpression) { override fun visitExpression(expression: FirExpression, data: FirElement) {
when (expression) { when (expression) {
is FirExpressionStub -> { is FirExpressionStub -> {
expressionStubs++ if (data !is FirProperty || data.isCatchParameter != true) {
println(expression.psi?.text) expressionStubs++
println(expression.psi?.text)
}
} }
else -> normalExpressions++ else -> normalExpressions++
} }
expression.acceptChildren(this) expression.acceptChildren(this, expression)
} }
override fun visitStatement(statement: FirStatement) { override fun visitStatement(statement: FirStatement, data: FirElement) {
normalStatements++ normalStatements++
statement.acceptChildren(this) statement.acceptChildren(this, statement)
} }
// override fun visitErrorDeclaration(errorDeclaration: FirErrorDeclaration) { // override fun visitErrorDeclaration(errorDeclaration: FirErrorDeclaration) {
@@ -111,11 +116,11 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() {
// errorDeclaration.psi?.let { println(it) } // errorDeclaration.psi?.let { println(it) }
// } // }
override fun visitDeclaration(declaration: FirDeclaration) { override fun visitDeclaration(declaration: FirDeclaration, data: FirElement) {
normalDeclarations++ normalDeclarations++
declaration.acceptChildren(this) declaration.acceptChildren(this, declaration)
} }
}) }, firFile)
ktFile.accept(object : KtTreeVisitor<Nothing?>() { ktFile.accept(object : KtTreeVisitor<Nothing?>() {
override fun visitReferenceExpression(expression: KtReferenceExpression, data: Nothing?): Void? { override fun visitReferenceExpression(expression: KtReferenceExpression, data: Nothing?): Void? {
ktReferences++ ktReferences++
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirPureAbstractElement import org.jetbrains.kotlin.fir.FirPureAbstractElement
import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.visitors.*
/* /*
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
abstract class FirCatch : FirPureAbstractElement(), FirElement { abstract class FirCatch : FirPureAbstractElement(), FirElement {
abstract override val source: KtSourceElement? abstract override val source: KtSourceElement?
abstract val parameter: FirValueParameter abstract val parameter: FirProperty
abstract val block: FirBlock abstract val block: FirBlock
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitCatch(this, data) override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitCatch(this, data)
@@ -10,7 +10,7 @@ package org.jetbrains.kotlin.fir.expressions.builder
import kotlin.contracts.* import kotlin.contracts.*
import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirBlock
import org.jetbrains.kotlin.fir.expressions.FirCatch import org.jetbrains.kotlin.fir.expressions.FirCatch
import org.jetbrains.kotlin.fir.expressions.impl.FirCatchImpl import org.jetbrains.kotlin.fir.expressions.impl.FirCatchImpl
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.fir.visitors.*
@FirBuilderDsl @FirBuilderDsl
class FirCatchBuilder { class FirCatchBuilder {
var source: KtSourceElement? = null var source: KtSourceElement? = null
lateinit var parameter: FirValueParameter lateinit var parameter: FirProperty
lateinit var block: FirBlock lateinit var block: FirBlock
fun build(): FirCatch { fun build(): FirCatch {
@@ -8,7 +8,7 @@
package org.jetbrains.kotlin.fir.expressions.impl package org.jetbrains.kotlin.fir.expressions.impl
import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirBlock
import org.jetbrains.kotlin.fir.expressions.FirCatch import org.jetbrains.kotlin.fir.expressions.FirCatch
import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.visitors.*
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.fir.visitors.*
internal class FirCatchImpl( internal class FirCatchImpl(
override val source: KtSourceElement?, override val source: KtSourceElement?,
override var parameter: FirValueParameter, override var parameter: FirProperty,
override var block: FirBlock, override var block: FirBlock,
) : FirCatch() { ) : FirCatch() {
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) { override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
@@ -142,3 +142,7 @@ var FirRegularClass.isJavaRecord: Boolean? by FirDeclarationDataRegistry.data(Is
private object IsJavaRecordComponentKey : FirDeclarationDataKey() private object IsJavaRecordComponentKey : FirDeclarationDataKey()
var FirFunction.isJavaRecordComponent: Boolean? by FirDeclarationDataRegistry.data(IsJavaRecordComponentKey) var FirFunction.isJavaRecordComponent: Boolean? by FirDeclarationDataRegistry.data(IsJavaRecordComponentKey)
private object IsCatchParameterProperty : FirDeclarationDataKey()
var FirProperty.isCatchParameter: Boolean? by FirDeclarationDataRegistry.data(IsCatchParameterProperty)
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.renderer package org.jetbrains.kotlin.fir.renderer
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.isCatchParameter
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
open class FirDeclarationRenderer { open class FirDeclarationRenderer {
@@ -32,8 +33,12 @@ open class FirDeclarationRenderer {
is FirAnonymousFunction -> (declaration.label?.let { "${it.name}@" } ?: "") + "fun" is FirAnonymousFunction -> (declaration.label?.let { "${it.name}@" } ?: "") + "fun"
is FirSimpleFunction -> "fun" is FirSimpleFunction -> "fun"
is FirProperty -> { is FirProperty -> {
val prefix = if (declaration.isLocal) "l" else "" if (declaration.isCatchParameter == true) {
prefix + if (declaration.isVal) "val" else "var" ""
} else {
val prefix = if (declaration.isLocal) "l" else ""
prefix + if (declaration.isVal) "val" else "var"
}
} }
is FirPropertyAccessor -> if (declaration.isGetter) "get" else "set" is FirPropertyAccessor -> if (declaration.isGetter) "get" else "set"
is FirField -> "field" is FirField -> "field"
@@ -181,7 +181,9 @@ class FirRenderer(
annotationRenderer?.render(callableDeclaration) annotationRenderer?.render(callableDeclaration)
visitMemberDeclaration(callableDeclaration) visitMemberDeclaration(callableDeclaration)
val receiverParameter = callableDeclaration.receiverParameter val receiverParameter = callableDeclaration.receiverParameter
print(" ") if (callableDeclaration !is FirProperty || callableDeclaration.isCatchParameter != true) {
print(" ")
}
if (receiverParameter != null) { if (receiverParameter != null) {
annotationRenderer?.render(receiverParameter, AnnotationUseSiteTarget.RECEIVER) annotationRenderer?.render(receiverParameter, AnnotationUseSiteTarget.RECEIVER)
receiverParameter.typeRef.accept(this) receiverParameter.typeRef.accept(this)
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.fir.tree.generator.FieldSets.typeArguments
import org.jetbrains.kotlin.fir.tree.generator.FieldSets.typeParameterRefs import org.jetbrains.kotlin.fir.tree.generator.FieldSets.typeParameterRefs
import org.jetbrains.kotlin.fir.tree.generator.FieldSets.typeParameters import org.jetbrains.kotlin.fir.tree.generator.FieldSets.typeParameters
import org.jetbrains.kotlin.fir.tree.generator.FieldSets.typeRefField import org.jetbrains.kotlin.fir.tree.generator.FieldSets.typeRefField
import org.jetbrains.kotlin.fir.tree.generator.FieldSets.valueParameters
import org.jetbrains.kotlin.fir.tree.generator.FieldSets.visibility import org.jetbrains.kotlin.fir.tree.generator.FieldSets.visibility
import org.jetbrains.kotlin.fir.tree.generator.context.AbstractFieldConfigurator import org.jetbrains.kotlin.fir.tree.generator.context.AbstractFieldConfigurator
import org.jetbrains.kotlin.fir.tree.generator.context.AbstractFirTreeBuilder import org.jetbrains.kotlin.fir.tree.generator.context.AbstractFirTreeBuilder
@@ -176,7 +175,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
} }
catchClause.configure { catchClause.configure {
+field("parameter", valueParameter).withTransform() +field("parameter", property).withTransform()
+field(block).withTransform() +field(block).withTransform()
needTransformOtherChildren() needTransformOtherChildren()
} }