From aef6787e87060ee5989a5c1847d4bb55a976febe Mon Sep 17 00:00:00 2001 From: "Anastasia.Nekrasova" Date: Thu, 24 Aug 2023 11:28:07 +0300 Subject: [PATCH] [Test] Add a test covering changes in the evaluation semantics of safe call with smart cast in K2 Addition to other safe call tests that are already present in tests. ^KT-41034 --- ...sticCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...agnosticCompilerFE10TestDataTestGenerated.java | 6 ++++++ ...htTreeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...FirPsiOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../tests/safeCalls/safeCallWithSmartCast.fir.kt | 15 +++++++++++++++ .../tests/safeCalls/safeCallWithSmartCast.kt | 15 +++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 7 files changed, 60 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.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 9ef515a7059..f0d9ad8881a 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 @@ -28485,6 +28485,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia public void testSafeCallOnFlexibleTypeAlias() throws Exception { runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt"); } + + @Test + @TestMetadata("safeCallWithSmartCast.kt") + public void testSafeCallWithSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt"); + } } @Nested 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 5f9297a4c2f..a443cabddc2 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 @@ -28485,6 +28485,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated public void testSafeCallOnFlexibleTypeAlias() throws Exception { runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt"); } + + @Test + @TestMetadata("safeCallWithSmartCast.kt") + public void testSafeCallWithSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt"); + } } @Nested 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 ffa1f0d8719..427a1ac0d48 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 @@ -28485,6 +28485,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir public void testSafeCallOnFlexibleTypeAlias() throws Exception { runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt"); } + + @Test + @TestMetadata("safeCallWithSmartCast.kt") + public void testSafeCallWithSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt"); + } } @Nested 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 bb40f23727e..6b274a35640 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 @@ -28497,6 +28497,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia public void testSafeCallOnFlexibleTypeAlias() throws Exception { runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt"); } + + @Test + @TestMetadata("safeCallWithSmartCast.kt") + public void testSafeCallWithSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt"); + } } @Nested diff --git a/compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.fir.kt b/compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.fir.kt new file mode 100644 index 00000000000..0fbed23ce49 --- /dev/null +++ b/compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.fir.kt @@ -0,0 +1,15 @@ +// WITH_STDLIB + +class C { + var x: Int = 0 +} + +fun test(с: C?, a: Any) { + с?.x = if (a is String) 0 else throw Exception(); + a.toUpperCase() +} + + +fun main(args: Array) { + test(null, 1) +} diff --git a/compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt b/compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt new file mode 100644 index 00000000000..f891067df77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt @@ -0,0 +1,15 @@ +// WITH_STDLIB + +class C { + var x: Int = 0 +} + +fun test(с: C?, a: Any) { + с?.x = if (a is String) 0 else throw Exception(); + a.toUpperCase() +} + + +fun main(args: Array) { + test(null, 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 d211b75efb3..e73a3673dad 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 @@ -30111,6 +30111,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testSafeCallOnFlexibleTypeAlias() throws Exception { runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt"); } + + @Test + @TestMetadata("safeCallWithSmartCast.kt") + public void testSafeCallWithSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallWithSmartCast.kt"); + } } @Nested