From d7e8dc65f5568228b63a0b17e0372fb6ae55de09 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Mon, 30 May 2022 16:18:26 +0300 Subject: [PATCH] [FIR] Update smartcast tests --- .../resolve/smartcasts/smartcastToNothing.dot | 95 +++++++++++++++++++ .../smartcasts/smartcastToNothing.fir.txt | 14 +++ .../resolve/smartcasts/smartcastToNothing.kt | 10 ++ 3 files changed, 119 insertions(+) diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot index c33a1005175..c231d723d65 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot @@ -312,4 +312,99 @@ digraph smartcastToNothing_kt { 106 -> {95} [color=red]; 106 -> {96} [color=green]; + subgraph cluster_26 { + color=red + 107 [label="Enter function test_1" style="filled" fillcolor=red]; + subgraph cluster_27 { + color=blue + 108 [label="Enter block"]; + subgraph cluster_28 { + color=blue + 109 [label="Enter when"]; + subgraph cluster_29 { + color=blue + 110 [label="Enter when branch condition "]; + 111 [label="Access variable R|/a|"]; + 112 [label="Type operator: (R|/a| is R|kotlin/Nothing?|)"]; + 113 [label="Exit when branch condition"]; + } + 114 [label="Synthetic else branch"]; + 115 [label="Enter when branch result"]; + subgraph cluster_30 { + color=blue + 116 [label="Enter block"]; + 117 [label="Access variable R|/a|"]; + 118 [label="Enter safe call"]; + 119 [label="Access variable R|kotlin/String.length|"]; + 120 [label="Exit safe call"]; + 121 [label="Variable declaration: lval b: R|kotlin/Int?|"]; + 122 [label="Exit block"]; + } + 123 [label="Exit when branch result"]; + 124 [label="Exit when"]; + } + subgraph cluster_31 { + color=blue + 125 [label="Enter when"]; + subgraph cluster_32 { + color=blue + 126 [label="Enter when branch condition "]; + 127 [label="Access variable R|/a|"]; + 128 [label="Type operator: (R|/a| is R|kotlin/Nothing|)"]; + 129 [label="Exit when branch condition"]; + } + 130 [label="Synthetic else branch"]; + 131 [label="Enter when branch result"]; + subgraph cluster_33 { + color=blue + 132 [label="Enter block"]; + 133 [label="Access variable R|/a|"]; + 134 [label="Stub" style="filled" fillcolor=gray]; + 135 [label="Access variable R|kotlin/String.length|" style="filled" fillcolor=gray]; + 136 [label="Variable declaration: lval b: R|kotlin/Int|" style="filled" fillcolor=gray]; + 137 [label="Exit block" style="filled" fillcolor=gray]; + } + 138 [label="Exit when branch result" style="filled" fillcolor=gray]; + 139 [label="Exit when"]; + } + 140 [label="Exit block"]; + } + 141 [label="Exit function test_1" style="filled" fillcolor=red]; + } + 107 -> {108}; + 108 -> {109}; + 109 -> {110}; + 110 -> {111}; + 111 -> {112}; + 112 -> {113}; + 113 -> {115 114}; + 114 -> {124}; + 115 -> {116}; + 116 -> {117}; + 117 -> {118 120}; + 118 -> {119}; + 119 -> {120}; + 120 -> {121}; + 121 -> {122}; + 122 -> {123}; + 123 -> {124}; + 124 -> {125}; + 125 -> {126}; + 126 -> {127}; + 127 -> {128}; + 128 -> {129}; + 129 -> {131 130}; + 130 -> {139}; + 131 -> {132}; + 132 -> {133}; + 133 -> {141} [label=onUncaughtException]; + 133 -> {134} [style=dotted]; + 134 -> {135} [style=dotted]; + 135 -> {136} [style=dotted]; + 136 -> {137} [style=dotted]; + 137 -> {138} [style=dotted]; + 138 -> {139} [style=dotted]; + 139 -> {140}; + 140 -> {141}; + } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt index b6ebf394306..5e53f372bf3 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt @@ -50,3 +50,17 @@ FILE: smartcastToNothing.kt } ) } } + public final fun test_1(a: R|kotlin/String?|): R|kotlin/Unit| { + when () { + (R|/a| is R|kotlin/Nothing?|) -> { + lval b: R|kotlin/Int?| = R|/a|?.{ $subj$.R|kotlin/String.length| } + } + } + + when () { + (R|/a| is R|kotlin/Nothing|) -> { + lval b: R|kotlin/Int| = R|/a|.R|kotlin/String.length| + } + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.kt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.kt index 8ed1de40206..7bf0acfa9b3 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.kt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.kt @@ -22,3 +22,13 @@ fun test_0(results: List) { } s?.let { it.a } } + +fun test_1(a: String?) { + if (a is Nothing?) { + val b = a?.length + } + + if (a is Nothing) { + val b = a.length + } +}