[FIR] Improve NO_ELSE_IN_WHEN message

This commit is contained in:
Kirill Rakhman
2023-12-21 14:13:03 +01:00
committed by Space Team
parent d5ed922208
commit 14bdcbfecd
3 changed files with 4 additions and 4 deletions
@@ -169,11 +169,11 @@ object FirDiagnosticRenderers {
val WHEN_MISSING_CASES = Renderer { missingCases: List<WhenMissingCase> ->
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"
}
}
@@ -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,
+1 -1
View File
@@ -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