From 5d6328a7063d76646abcfe07592bfc5aad145bf1 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 4 Jul 2023 09:29:54 +0300 Subject: [PATCH] [Test] Add test for KT-53460 --- ...osticCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...iagnosticCompilerFE10TestDataTestGenerated.java | 6 ++++++ ...ghtTreeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../FirPsiOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../notUselessComparasionAfterSmartcast.fir.kt | 14 ++++++++++++++ .../notUselessComparasionAfterSmartcast.kt | 14 ++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 7 files changed, 58 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.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 6cc10628406..15b38209167 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 @@ -22924,6 +22924,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt"); } + @Test + @TestMetadata("notUselessComparasionAfterSmartcast.kt") + public void testNotUselessComparasionAfterSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt"); + } + @Test @TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt") public void testNullAssertOnTypeWithNullableUpperBound() throws Exception { 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 91dfea84756..e6ddf58c46d 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 @@ -22924,6 +22924,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt"); } + @Test + @TestMetadata("notUselessComparasionAfterSmartcast.kt") + public void testNotUselessComparasionAfterSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt"); + } + @Test @TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt") public void testNullAssertOnTypeWithNullableUpperBound() throws Exception { 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 ac14b283c10..193972f706b 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 @@ -22924,6 +22924,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt"); } + @Test + @TestMetadata("notUselessComparasionAfterSmartcast.kt") + public void testNotUselessComparasionAfterSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt"); + } + @Test @TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt") public void testNullAssertOnTypeWithNullableUpperBound() throws Exception { 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 259c1dd17c9..ab7bb65a132 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 @@ -22930,6 +22930,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt"); } + @Test + @TestMetadata("notUselessComparasionAfterSmartcast.kt") + public void testNotUselessComparasionAfterSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt"); + } + @Test @TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt") public void testNullAssertOnTypeWithNullableUpperBound() throws Exception { diff --git a/compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.fir.kt new file mode 100644 index 00000000000..727fd57d1c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.fir.kt @@ -0,0 +1,14 @@ +// ISSUE: KT-53460 + +fun test(a: String?, b: String?) { + if (a == null || a == "foo") { + when (b) { + "abc" -> return + } + } + + a.length // should be an error + if (a == null || a == "bar") { // comparasion to null is not useless + a.length + } +} diff --git a/compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt b/compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt new file mode 100644 index 00000000000..00d00c848a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt @@ -0,0 +1,14 @@ +// ISSUE: KT-53460 + +fun test(a: String?, b: String?) { + if (a == null || a == "foo") { + when (b) { + "abc" -> return + } + } + + a.length // should be an error + if (a == null || a == "bar") { // comparasion to null is not useless + a.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 e5f57f3c7db..a41f8e7ea89 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 @@ -23762,6 +23762,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/nullableTypes/kt58844.kt"); } + @Test + @TestMetadata("notUselessComparasionAfterSmartcast.kt") + public void testNotUselessComparasionAfterSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullableTypes/notUselessComparasionAfterSmartcast.kt"); + } + @Test @TestMetadata("nullAssertOnTypeWithNullableUpperBound.kt") public void testNullAssertOnTypeWithNullableUpperBound() throws Exception {