From d01a2c7271f9768b43c56f4f4a5a985ccb828c50 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 24 Jan 2023 16:43:01 +0200 Subject: [PATCH] [Test] Add test for KT-45814 ^KT-45814 Can't reproduce --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../tests/smartCasts/kt45814.fir.kt | 23 +++++++++++++++++++ .../diagnostics/tests/smartCasts/kt45814.kt | 23 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 6 files changed, 70 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt45814.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt45814.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 54311c1cca1..f7d49a7a1e0 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -29542,6 +29542,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/smartCasts/kt3993.kt"); } + @Test + @TestMetadata("kt45814.kt") + public void testKt45814() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt45814.kt"); + } + @Test @TestMetadata("kt51460.kt") public void testKt51460() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 6f894e50095..8ad156abdf7 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -29638,6 +29638,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/smartCasts/kt3993.kt"); } + @Test + @TestMetadata("kt45814.kt") + public void testKt45814() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt45814.kt"); + } + @Test @TestMetadata("kt51460.kt") public void testKt51460() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index c954aa16a47..f0de1c2ed67 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -29542,6 +29542,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/smartCasts/kt3993.kt"); } + @Test + @TestMetadata("kt45814.kt") + public void testKt45814() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt45814.kt"); + } + @Test @TestMetadata("kt51460.kt") public void testKt51460() throws Exception { diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt45814.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt45814.fir.kt new file mode 100644 index 00000000000..464b0dd6689 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt45814.fir.kt @@ -0,0 +1,23 @@ +// SKIP_TXT +// ISSUE: KT-45814 + +class Foo(val bar: String?) + +fun test_1(foo: Foo?) { + foo!!.bar.let { + foo?.bar?.length // Unnecessary + foo.bar?.length // Correct + foo?.bar?.length // Unnecessary + } + foo.bar?.length + foo?.bar?.length // Unnecessary +} + +fun test_2(foo: Foo?) { + foo!!.bar.let { + foo.bar?.length // Correct + foo?.bar?.length // Unnecessary + Unit + } + foo.bar?.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt45814.kt b/compiler/testData/diagnostics/tests/smartCasts/kt45814.kt new file mode 100644 index 00000000000..7bada53e26c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt45814.kt @@ -0,0 +1,23 @@ +// SKIP_TXT +// ISSUE: KT-45814 + +class Foo(val bar: String?) + +fun test_1(foo: Foo?) { + foo!!.bar.let { + foo?.bar?.length // Unnecessary + foo.bar?.length // Correct + foo?.bar?.length // Unnecessary + } + foo.bar?.length + foo?.bar?.length // Unnecessary +} + +fun test_2(foo: Foo?) { + foo!!.bar.let { + foo.bar?.length // Correct + foo?.bar?.length // Unnecessary + Unit + } + foo.bar?.length +} 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 0090b3f5d8a..6e51290318c 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 @@ -29638,6 +29638,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/kt3993.kt"); } + @Test + @TestMetadata("kt45814.kt") + public void testKt45814() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt45814.kt"); + } + @Test @TestMetadata("kt51460.kt") public void testKt51460() throws Exception {