From 737c8c20f66a1841d47bc0a542ad2871b165f660 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Mon, 15 May 2023 11:33:06 +0300 Subject: [PATCH] [FIR] KT-58674: Ensure loop conditions have no expected type in K2 --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 ++++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../tests/whileConditionExpectedType.fir.kt | 21 +++++++++++++++++++ .../tests/whileConditionExpectedType.kt | 21 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 7 files changed, 72 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/whileConditionExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/whileConditionExpectedType.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 770e1429af4..c5493ac5adc 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 @@ -1257,6 +1257,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/Variance.kt"); } + @Test + @TestMetadata("whileConditionExpectedType.kt") + public void testWhileConditionExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/whileConditionExpectedType.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/annotations") @TestDataPath("$PROJECT_ROOT") 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 27e6005eb03..82b8a36a909 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 @@ -1257,6 +1257,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/Variance.kt"); } + @Test + @TestMetadata("whileConditionExpectedType.kt") + public void testWhileConditionExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/whileConditionExpectedType.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/annotations") @TestDataPath("$PROJECT_ROOT") 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 4dffa06ac4b..2aee10868b1 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 @@ -1257,6 +1257,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/Variance.kt"); } + @Test + @TestMetadata("whileConditionExpectedType.kt") + public void testWhileConditionExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/whileConditionExpectedType.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/annotations") @TestDataPath("$PROJECT_ROOT") 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 2e034534aeb..89641e4a5a0 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 @@ -1257,6 +1257,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/Variance.kt"); } + @Test + @TestMetadata("whileConditionExpectedType.kt") + public void testWhileConditionExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/whileConditionExpectedType.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/annotations") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/testData/diagnostics/tests/whileConditionExpectedType.fir.kt b/compiler/testData/diagnostics/tests/whileConditionExpectedType.fir.kt new file mode 100644 index 00000000000..a9732dde4a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/whileConditionExpectedType.fir.kt @@ -0,0 +1,21 @@ +// ISSUE: KT-58674 +// INFERENCE_HELPERS + +fun test() { + while (materialize()) { // K1: OK, K2: NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER + + } + + do { + + } while (materialize()) // K1: OK, K2: NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER + + if (materialize()) { + + } + + when (val it = materialize()) { + materialize() -> {} + else -> {} + } +} diff --git a/compiler/testData/diagnostics/tests/whileConditionExpectedType.kt b/compiler/testData/diagnostics/tests/whileConditionExpectedType.kt new file mode 100644 index 00000000000..14244337fdd --- /dev/null +++ b/compiler/testData/diagnostics/tests/whileConditionExpectedType.kt @@ -0,0 +1,21 @@ +// ISSUE: KT-58674 +// INFERENCE_HELPERS + +fun test() { + while (materialize()) { // K1: OK, K2: NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER + + } + + do { + + } while (materialize()) // K1: OK, K2: NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER + + if (materialize()) { + + } + + when (val it = materialize()) { + materialize() -> {} + else -> {} + } +} 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 bed0962eeb3..cba89e3c2e0 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 @@ -1257,6 +1257,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/Variance.kt"); } + @Test + @TestMetadata("whileConditionExpectedType.kt") + public void testWhileConditionExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/whileConditionExpectedType.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/annotations") @TestDataPath("$PROJECT_ROOT")