KT-10295: long enum (sealed) special case

This commit is contained in:
Mikhail Glukhikh
2016-01-11 17:21:03 +03:00
parent c085eb650f
commit 936fee0afa
2 changed files with 13 additions and 2 deletions
@@ -411,11 +411,14 @@ object Renderers {
append("(").append(renderTypes(inferenceErrorData.valueArgumentsTypes)).append(")")
}
private val WHEN_MISSING_LIMIT = 7
@JvmField val RENDER_WHEN_MISSING_CASES: Renderer<List<WhenMissingCase>> = Renderer {
if (!it.hasUnknown) {
val list = it.map { "'$it'" }.joinToString(", ")
val list = it.take(WHEN_MISSING_LIMIT).map { "'$it'" }.joinToString(", ")
val branches = if (it.size > 1) "branches" else "branch"
"$list $branches or 'else' branch instead"
val others = if (it.size > WHEN_MISSING_LIMIT) ", ..." else ""
"$list$others $branches or 'else' branch instead"
}
else {
"'else' branch"
+8
View File
@@ -28,6 +28,14 @@ fun whenOnEnum(c: Color) {
}
}
enum class EnumInt {
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15
}
fun whenOnLongEnum(i: EnumInt) = <error descr="[NO_ELSE_IN_WHEN] when expression must be exhaustive, add necessary 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', ... branches or 'else' branch instead">when</error> (i) {
EnumInt.A7 -> 7
}
sealed class Variant {
object Singleton : Variant()