From c6c0abae82ddb5fd9dc7448b8f4fff0720af8248 Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Fri, 8 Mar 2024 09:37:13 -0600 Subject: [PATCH] [FIR] Create test case to validate KT-56988 is working as expected ^KT-56988 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 ++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 ++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 ++++ .../smartcasts/whileLoopNotNull.fir.kt | 22 +++++++++++++++ .../smartcasts/whileLoopNotNull.fir.txt | 28 +++++++++++++++++++ .../smartcasts/whileLoopNotNull.kt | 22 +++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++ 8 files changed, 102 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 82207710a6a..8463b71bbda 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -47140,6 +47140,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.kt"); } + @Test + @TestMetadata("whileLoopNotNull.kt") + public void testWhileLoopNotNull() { + runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt"); + } + @Test @TestMetadata("withChangesToNull.kt") public void testWithChangesToNull() { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 3434840afe8..4c40467515d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -47140,6 +47140,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.kt"); } + @Test + @TestMetadata("whileLoopNotNull.kt") + public void testWhileLoopNotNull() { + runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt"); + } + @Test @TestMetadata("withChangesToNull.kt") public void testWithChangesToNull() { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index c1e1e395cab..a4daa463346 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -44770,6 +44770,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.kt"); } + @Test + @TestMetadata("whileLoopNotNull.kt") + public void testWhileLoopNotNull() { + runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt"); + } + @Test @TestMetadata("withChangesToNull.kt") public void testWithChangesToNull() { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index aafff6f79f1..8d09afc54ce 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -44908,6 +44908,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.kt"); } + @Test + @TestMetadata("whileLoopNotNull.kt") + public void testWhileLoopNotNull() { + runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt"); + } + @Test @TestMetadata("withChangesToNull.kt") public void testWithChangesToNull() { diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.kt new file mode 100644 index 00000000000..731d5c86e18 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.kt @@ -0,0 +1,22 @@ +// FIR_DUMP + +fun Int?.swap(): Int = 1 +fun Int.swap(): Int? = null + +var result = false + +fun b(): Boolean { + result = !result + return result +} + +fun test() { + var x: Int? = 1 + if (x != null) { + while (b()) { + val tmp = x.swap() + x = tmp + } + x.plus(1) + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.txt new file mode 100644 index 00000000000..c448d2b3072 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.fir.txt @@ -0,0 +1,28 @@ +FILE: whileLoopNotNull.fir.kt + public final fun R|kotlin/Int?|.swap(): R|kotlin/Int| { + ^swap Int(1) + } + public final fun R|kotlin/Int|.swap(): R|kotlin/Int?| { + ^swap Null(null) + } + public final var result: R|kotlin/Boolean| = Boolean(false) + public get(): R|kotlin/Boolean| + public set(value: R|kotlin/Boolean|): R|kotlin/Unit| + public final fun b(): R|kotlin/Boolean| { + R|/result| = R|/result|.R|kotlin/Boolean.not|() + ^b R|/result| + } + public final fun test(): R|kotlin/Unit| { + lvar x: R|kotlin/Int?| = Int(1) + when () { + !=(R|/x|, Null(null)) -> { + while(R|/b|()) { + lval tmp: R|kotlin/Int| = R|/x|.R|/swap|() + R|/x| = R|/tmp| + } + + R|/x|.R|kotlin/Int.plus|(Int(1)) + } + } + + } diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt new file mode 100644 index 00000000000..d4bbf39c684 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt @@ -0,0 +1,22 @@ +// FIR_DUMP + +fun Int?.swap(): Int = 1 +fun Int.swap(): Int? = null + +var result = false + +fun b(): Boolean { + result = !result + return result +} + +fun test() { + var x: Int? = 1 + if (x != null) { + while (b()) { + val tmp = x.swap() + x = tmp + } + x.plus(1) + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index dfdc007a9d2..a9ae207643c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -47198,6 +47198,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/unsoundSmartcast.kt"); } + @Test + @TestMetadata("whileLoopNotNull.kt") + public void testWhileLoopNotNull() { + runTest("compiler/testData/diagnostics/testsWithStdLib/smartcasts/whileLoopNotNull.kt"); + } + @Test @TestMetadata("withChangesToNull.kt") public void testWithChangesToNull() {