From bcd06ef310096c3654218cee687e6c4f15b5b5b4 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Thu, 10 Feb 2022 14:41:28 +0300 Subject: [PATCH] Make error message for captured generic type parameters much more straightforward 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