From 890418f6b70ed0f4f8c2f33316eae16dba7e053e Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 20 Dec 2022 11:09:14 +0200 Subject: [PATCH] [FE] Add detailed report to possible failures in ComponentArrayOwner.registerComponent --- .../kotlin/util/ComponentArrayOwner.kt | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/core/compiler.common/src/org/jetbrains/kotlin/util/ComponentArrayOwner.kt b/core/compiler.common/src/org/jetbrains/kotlin/util/ComponentArrayOwner.kt index ce857dc4c36..d8b81281c68 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/util/ComponentArrayOwner.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/util/ComponentArrayOwner.kt @@ -16,11 +16,34 @@ abstract class ComponentArrayOwner : AbstractArrayMapOwner, value: V) { - arrayMap[typeRegistry.getId(tClass)] = value + val id = typeRegistry.getId(tClass) + try { + arrayMap[id] = value + } catch (e: Exception) { + throw RuntimeException(createDiagnosticMessage(id, tClass), e) + } } protected operator fun get(key: KClass): V { val id = typeRegistry.getId(key) return arrayMap[id] ?: error("No '$key'($id) component in array: $this") } -} \ No newline at end of file + + private fun createDiagnosticMessage(id: Int, tClass: KClass<*>): String = buildString { + appendLine("Error occurred during registration of component in array") + appendLine("Currently registered") + appendLine(" $id: $tClass") + appendLine("Registrar:") + for ((kClass, x) in typeRegistry.allValuesThreadUnsafeForRendering()) { + appendLine(" $x: $kClass") + } + appendLine("Array map:") + for (i in 0 until arrayMap.size) { + var element: Any? = arrayMap[i] + if (element != null) { + element = element::class + } + appendLine(" $i: $element") + } + } +}