From 8320668485e2bc93d6851b15406ddf4c3ac0e69b Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Fri, 1 Mar 2024 09:27:24 -0600 Subject: [PATCH] [FIR] Adding a test case to show resolution of KT-29559 in K2 --- ...CompilerTestFE10TestdataTestGenerated.java | 12 +++++++++ ...sticCompilerFE10TestDataTestGenerated.java | 12 +++++++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 12 +++++++++ ...siOldFrontendDiagnosticsTestGenerated.java | 12 +++++++++ .../tests/postfixIncSmartCast.fir.kt | 11 ++++++++ .../diagnostics/tests/postfixIncSmartCast.kt | 11 ++++++++ .../incrementAfterAssignment.fir.kt | 27 +++++++++++++++++++ .../smartCasts/incrementAfterAssignment.kt | 27 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 12 +++++++++ 9 files changed, 136 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/postfixIncSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/postfixIncSmartCast.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.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 454ab01c83f..d2f466698e7 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 @@ -1089,6 +1089,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/phantomIntersections.kt"); } + @Test + @TestMetadata("postfixIncSmartCast.kt") + public void testPostfixIncSmartCast() { + runTest("compiler/testData/diagnostics/tests/postfixIncSmartCast.kt"); + } + @Test @TestMetadata("prefixIncReturnType.kt") public void testPrefixIncReturnType() { @@ -35518,6 +35524,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt"); } + @Test + @TestMetadata("incrementAfterAssignment.kt") + public void testIncrementAfterAssignment() { + runTest("compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt"); + } + @Test @TestMetadata("kt10232.kt") public void testKt10232() { 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 38528dfa600..a7a7a332475 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 @@ -1089,6 +1089,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/phantomIntersections.kt"); } + @Test + @TestMetadata("postfixIncSmartCast.kt") + public void testPostfixIncSmartCast() { + runTest("compiler/testData/diagnostics/tests/postfixIncSmartCast.kt"); + } + @Test @TestMetadata("prefixIncReturnType.kt") public void testPrefixIncReturnType() { @@ -35518,6 +35524,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt"); } + @Test + @TestMetadata("incrementAfterAssignment.kt") + public void testIncrementAfterAssignment() { + runTest("compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt"); + } + @Test @TestMetadata("kt10232.kt") public void testKt10232() { 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 455c81bc9f1..e92e62a43d2 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 @@ -1089,6 +1089,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/phantomIntersections.kt"); } + @Test + @TestMetadata("postfixIncSmartCast.kt") + public void testPostfixIncSmartCast() { + runTest("compiler/testData/diagnostics/tests/postfixIncSmartCast.kt"); + } + @Test @TestMetadata("prefixIncReturnType.kt") public void testPrefixIncReturnType() { @@ -33090,6 +33096,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt"); } + @Test + @TestMetadata("incrementAfterAssignment.kt") + public void testIncrementAfterAssignment() { + runTest("compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt"); + } + @Test @TestMetadata("kt10232.kt") public void testKt10232() { 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 40db665ccfc..4750bbb9895 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 @@ -1089,6 +1089,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/phantomIntersections.kt"); } + @Test + @TestMetadata("postfixIncSmartCast.kt") + public void testPostfixIncSmartCast() { + runTest("compiler/testData/diagnostics/tests/postfixIncSmartCast.kt"); + } + @Test @TestMetadata("prefixIncReturnType.kt") public void testPrefixIncReturnType() { @@ -33228,6 +33234,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt"); } + @Test + @TestMetadata("incrementAfterAssignment.kt") + public void testIncrementAfterAssignment() { + runTest("compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt"); + } + @Test @TestMetadata("kt10232.kt") public void testKt10232() { diff --git a/compiler/testData/diagnostics/tests/postfixIncSmartCast.fir.kt b/compiler/testData/diagnostics/tests/postfixIncSmartCast.fir.kt new file mode 100644 index 00000000000..41f2f51b0ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/postfixIncSmartCast.fir.kt @@ -0,0 +1,11 @@ +open class I { + operator fun inc(): ST = ST() +} + +class ST : I() + +fun main() { + var local = I() + val x: ST = local++ + val y: ST = local +} diff --git a/compiler/testData/diagnostics/tests/postfixIncSmartCast.kt b/compiler/testData/diagnostics/tests/postfixIncSmartCast.kt new file mode 100644 index 00000000000..bad4e4a6e02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/postfixIncSmartCast.kt @@ -0,0 +1,11 @@ +open class I { + operator fun inc(): ST = ST() +} + +class ST : I() + +fun main() { + var local = I() + val x: ST = local++ + val y: ST = local +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.fir.kt new file mode 100644 index 00000000000..6ebf323d99a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.fir.kt @@ -0,0 +1,27 @@ +// WITH_STDLIB +// SKIP_TEXT +// ISSUE: KT-29559 + +fun consume(i: Int) {} +fun consume(c: Char) {} +fun consume(a: Any?) {} + +fun test1() { + var a: Any + + a = 1 + consume(a) + + a = 1 + consume(a++) + + a = 1 + consume(++a) + + a = 't' + consume(a++) + + a = 't' + consume(++a) + consume(a++) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt b/compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt new file mode 100644 index 00000000000..458406ecdac --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt @@ -0,0 +1,27 @@ +// WITH_STDLIB +// SKIP_TEXT +// ISSUE: KT-29559 + +fun consume(i: Int) {} +fun consume(c: Char) {} +fun consume(a: Any?) {} + +fun test1() { + var a: Any + + a = 1 + consume(a) + + a = 1 + consume(a++) + + a = 1 + consume(++a) + + a = 't' + consume(a++) + + a = 't' + consume(++a) + consume(a++) +} 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 89ce284fa01..efd420fa867 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 @@ -1089,6 +1089,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/phantomIntersections.kt"); } + @Test + @TestMetadata("postfixIncSmartCast.kt") + public void testPostfixIncSmartCast() { + runTest("compiler/testData/diagnostics/tests/postfixIncSmartCast.kt"); + } + @Test @TestMetadata("prefixIncReturnType.kt") public void testPrefixIncReturnType() { @@ -35518,6 +35524,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/incDecToNull.kt"); } + @Test + @TestMetadata("incrementAfterAssignment.kt") + public void testIncrementAfterAssignment() { + runTest("compiler/testData/diagnostics/tests/smartCasts/incrementAfterAssignment.kt"); + } + @Test @TestMetadata("kt10232.kt") public void testKt10232() {