From 370a6fb461785103a84a69ec0f6110bc77520fd1 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Fri, 8 Sep 2023 12:50:03 +0200 Subject: [PATCH] KT-61728 [LL API] Add extra test for smartcast inside `let` --- .../smartCasts/insideLetOnNullableReceiver.kt | 7 ++++ .../insideLetOnNullableReceiver.txt | 40 +++++++++++++++++++ .../ContextCollectorSourceTestGenerated.java | 6 +++ 3 files changed, 53 insertions(+) create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.kt create mode 100644 analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.txt diff --git a/analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.kt b/analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.kt new file mode 100644 index 00000000000..25b6a5b84b5 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.kt @@ -0,0 +1,7 @@ +fun foo(param: String?): String { + param?.let { + return param + } + + return "" +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.txt b/analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.txt new file mode 100644 index 00000000000..44422db7cab --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.txt @@ -0,0 +1,40 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol param: R|kotlin/String?| + Element 8 + Scope: FirLocalScope + Element 9 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol it: R|kotlin/String| + Element 10 + Scope: FirLocalScope +Smart Casts: + FirValueParameterSymbol param: R|kotlin/String?| + Types: + kotlin/Any + +FILE: [ResolvedTo(IMPORTS)] insideLetOnNullableReceiver.kt + public final [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] param: R|kotlin/String?|): R|kotlin/String| { + R|/param|?.{ $subj$.R|kotlin/let|( = [ResolvedTo(BODY_RESOLVE)] let@fun ([ResolvedTo(BODY_RESOLVE)] it: R|kotlin/String|): R|kotlin/Nothing| { + ^foo R|/param| + } + ) } + ^foo String() + } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java index a0e4e6be8be..340f03eb00a 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java @@ -257,6 +257,12 @@ public class ContextCollectorSourceTestGenerated extends AbstractContextCollecto runTest("analysis/low-level-api-fir/testdata/contextCollector/smartCasts/extensionReceiver.kt"); } + @Test + @TestMetadata("insideLetOnNullableReceiver.kt") + public void testInsideLetOnNullableReceiver() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/smartCasts/insideLetOnNullableReceiver.kt"); + } + @Test @TestMetadata("insideLoop.kt") public void testInsideLoop() throws Exception {