diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt index 35847e12432..1ec909d9fc5 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt @@ -38,9 +38,9 @@ class TypeDeserializer( computeTypeAliasDescriptor(fqNameIndex) } - private val typeParameterDescriptors = + private val typeParameterDescriptors: Map = if (typeParameterProtos.isEmpty()) { - mapOf() + emptyMap() } else { val result = LinkedHashMap() for ((index, proto) in typeParameterProtos.withIndex()) { @@ -133,22 +133,24 @@ class TypeDeserializer( return c.components.notFoundClasses.getClass(classId, typeParametersCount) } - return when { - proto.hasClassName() -> (classifierDescriptors(proto.className) ?: notFoundClass(proto.className)).typeConstructor + val classifier = when { + proto.hasClassName() -> + classifierDescriptors(proto.className) ?: notFoundClass(proto.className) proto.hasTypeParameter() -> - typeParameterTypeConstructor(proto.typeParameter) - ?: ErrorUtils.createErrorTypeConstructor( + loadTypeParameter(proto.typeParameter) + ?: return ErrorUtils.createErrorTypeConstructor( "Unknown type parameter ${proto.typeParameter}. Please try recompiling module containing \"$containerPresentableName\"" ) proto.hasTypeParameterName() -> { - val container = c.containingDeclaration val name = c.nameResolver.getString(proto.typeParameterName) - val parameter = ownTypeParameters.find { it.name.asString() == name } - parameter?.typeConstructor ?: ErrorUtils.createErrorTypeConstructor("Deserialized type parameter $name in $container") + ownTypeParameters.find { it.name.asString() == name } + ?: return ErrorUtils.createErrorTypeConstructor("Deserialized type parameter $name in ${c.containingDeclaration}") } - proto.hasTypeAliasName() -> (typeAliasDescriptors(proto.typeAliasName) ?: notFoundClass(proto.typeAliasName)).typeConstructor - else -> ErrorUtils.createErrorTypeConstructor("Unknown type") + proto.hasTypeAliasName() -> + typeAliasDescriptors(proto.typeAliasName) ?: notFoundClass(proto.typeAliasName) + else -> return ErrorUtils.createErrorTypeConstructor("Unknown type") } + return classifier.typeConstructor } private fun createSuspendFunctionType( @@ -233,8 +235,8 @@ class TypeDeserializer( ).makeNullableAsSpecified(funType.isMarkedNullable) } - private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? = - typeParameterDescriptors[typeParameterId]?.typeConstructor ?: parent?.typeParameterTypeConstructor(typeParameterId) + private fun loadTypeParameter(typeParameterId: Int): TypeParameterDescriptor? = + typeParameterDescriptors[typeParameterId] ?: parent?.loadTypeParameter(typeParameterId) private fun computeClassifierDescriptor(fqNameIndex: Int): ClassifierDescriptor? { val id = c.nameResolver.getClassId(fqNameIndex)