From 83003e02cb7d7bac346b55c854683ca315d39530 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Thu, 17 Feb 2022 05:06:20 -0800 Subject: [PATCH] Make error message for captured generic type parameters much more straightforward (#1863) Fixes #1860 --- .../src/kotlinx/serialization/internal/Platform.common.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt b/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt index 590376a72..fde2c36a8 100644 --- a/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt +++ b/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt @@ -99,6 +99,11 @@ internal expect fun KClass<*>.platformSpecificSerializerNotRegistered(): Nothing @Suppress("UNCHECKED_CAST") internal fun KType.kclass() = when (val t = classifier) { is KClass<*> -> t + is KTypeParameter -> { + error("Captured type paramerer $t from generic non-reified function. " + + "Such functionality cannot be supported as $t is erased, either specify serializer explicitly or make " + + "calling function inline with reified $t") + } else -> error("Only KClass supported as classifier, got $t") } as KClass