From 14bdcbfecd8cfdc284d7d7ccd7e969992999a6f1 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Thu, 21 Dec 2023 14:13:03 +0100 Subject: [PATCH] [FIR] Improve NO_ELSE_IN_WHEN message --- .../kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt | 4 ++-- .../fir/analysis/diagnostics/FirErrorsDefaultMessages.kt | 2 +- compiler/testData/cli/jvm/returnAsWhenKey.out | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt index 6f78fb67be4..d9e3b01a021 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt @@ -169,11 +169,11 @@ object FirDiagnosticRenderers { val WHEN_MISSING_CASES = Renderer { missingCases: List -> if (missingCases.singleOrNull() == WhenMissingCase.Unknown) { - "'else' branch" + "an 'else' branch" } else { val list = missingCases.joinToString(", ", limit = WHEN_MISSING_LIMIT) { "'$it'" } val branches = if (missingCases.size > 1) "branches" else "branch" - "$list $branches or 'else' branch instead" + "the $list $branches or an 'else' branch" } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt index 8fbca8bd847..ad74f32cad5 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt @@ -2228,7 +2228,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { // When expressions map.put(EXPECTED_CONDITION, "Condition of type 'Boolean' expected.") - map.put(NO_ELSE_IN_WHEN, "''when'' expression must be exhaustive. Add the necessary {0}{1}", WHEN_MISSING_CASES, STRING) + map.put(NO_ELSE_IN_WHEN, "''when'' expression must be exhaustive. Add {0}{1}.", WHEN_MISSING_CASES, STRING) map.put(INVALID_IF_AS_EXPRESSION, "'if' must have both main and 'else' branches when used as an expression.") map.put( NON_EXHAUSTIVE_WHEN_STATEMENT, diff --git a/compiler/testData/cli/jvm/returnAsWhenKey.out b/compiler/testData/cli/jvm/returnAsWhenKey.out index 74881c39cb2..00df6eda40b 100644 --- a/compiler/testData/cli/jvm/returnAsWhenKey.out +++ b/compiler/testData/cli/jvm/returnAsWhenKey.out @@ -1,4 +1,4 @@ -compiler/testData/cli/jvm/returnAsWhenKey.kt:4:5: error: 'when' expression must be exhaustive. Add the necessary 'true', 'false' branches or 'else' branch instead +compiler/testData/cli/jvm/returnAsWhenKey.kt:4:5: error: 'when' expression must be exhaustive. Add the 'true', 'false' branches or an 'else' branch. when (true) { ^ COMPILATION_ERROR