From 936fee0afac3ac947b21dd418aebbbfc9296b0e0 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 11 Jan 2016 17:21:03 +0300 Subject: [PATCH] KT-10295: long enum (sealed) special case --- .../jetbrains/kotlin/diagnostics/rendering/Renderers.kt | 7 +++++-- idea/testData/checker/WhenNonExhaustive.kt | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt index 86fbdc85a1b..11fa3a190b5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt @@ -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> = 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" diff --git a/idea/testData/checker/WhenNonExhaustive.kt b/idea/testData/checker/WhenNonExhaustive.kt index 4ccc6c7e4c3..ebb895904d4 100644 --- a/idea/testData/checker/WhenNonExhaustive.kt +++ b/idea/testData/checker/WhenNonExhaustive.kt @@ -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) = when (i) { + EnumInt.A7 -> 7 +} + sealed class Variant { object Singleton : Variant()