diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMapperUtils.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMapperUtils.kt index 01251803910..97f3323d078 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMapperUtils.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMapperUtils.kt @@ -37,12 +37,11 @@ fun patchTypeParametersForDefaultImplMethod(function: CallableMemberDescriptor): val existingNames = (functionTypeParameterNames + interfaceTypeParameters.map { it.name.asString() }).toMutableSet() - val mappingForInterfaceTypeParameters = conflictedTypeParameters.associateBy ({ it }) { - typeParameter -> + val mappingForInterfaceTypeParameters = conflictedTypeParameters.associateBy({ it }) { typeParameter -> val newNamePrefix = typeParameter.name.asString() + "_I" - val newName = newNamePrefix + generateSequence(1) { x -> x + 1 }.first { - index -> (newNamePrefix + index) !in existingNames + val newName = newNamePrefix + generateSequence(1) { x -> x + 1 }.first { index -> + (newNamePrefix + index) !in existingNames } existingNames.add(newName) @@ -58,21 +57,25 @@ fun patchTypeParametersForDefaultImplMethod(function: CallableMemberDescriptor): val additionalTypeParameters = interfaceTypeParameters.map { typeParameter -> mappingForInterfaceTypeParameters[typeParameter] ?: typeParameter } - var resultTypeParameters = mutableListOf() + val resultTypeParameters = mutableListOf() DescriptorSubstitutor.substituteTypeParameters(additionalTypeParameters, substitution, classDescriptor, resultTypeParameters) return ReceiverTypeAndTypeParameters(substitutor.substitute(classDescriptor.defaultType, Variance.INVARIANT)!!, resultTypeParameters) } -fun CallableMemberDescriptor.createTypeParameterWithNewName(descriptor: TypeParameterDescriptor, newName: String): TypeParameterDescriptorImpl { +fun CallableMemberDescriptor.createTypeParameterWithNewName( + descriptor: TypeParameterDescriptor, + newName: String +): TypeParameterDescriptorImpl { val newDescriptor = TypeParameterDescriptorImpl.createForFurtherModification( - this, - descriptor.annotations, - descriptor.isReified, - descriptor.variance, - Name.identifier(newName), - descriptor.index, - descriptor.source) + this, + descriptor.annotations, + descriptor.isReified, + descriptor.variance, + Name.identifier(newName), + descriptor.index, + descriptor.source + ) descriptor.upperBounds.forEach { newDescriptor.addUpperBound(it) } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt index 665ed4d60e3..1002bf70322 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt @@ -83,7 +83,7 @@ fun mapType( val descriptor = constructor.declarationDescriptor - ?: throw UnsupportedOperationException("no descriptor for type constructor of " + kotlinType) + ?: throw UnsupportedOperationException("no descriptor for type constructor of $kotlinType") when { ErrorUtils.isError(descriptor) -> { @@ -148,19 +148,21 @@ fun mapType( factory.javaLangClassType } else { typeMappingConfiguration.getPredefinedTypeForClass(descriptor.original) - ?: run { - // refer to enum entries by enum type in bytecode unless ASM_TYPE is written - val enumClassIfEnumEntry = if (descriptor.kind == ClassKind.ENUM_ENTRY) + ?: run { + // refer to enum entries by enum type in bytecode unless ASM_TYPE is written + val enumClassIfEnumEntry = + if (descriptor.kind == ClassKind.ENUM_ENTRY) descriptor.containingDeclaration as ClassDescriptor - else descriptor - factory.createObjectType( - computeInternalName( - enumClassIfEnumEntry.original, - typeMappingConfiguration, - isIrBackend - ) + else + descriptor + factory.createObjectType( + computeInternalName( + enumClassIfEnumEntry.original, + typeMappingConfiguration, + isIrBackend ) - } + ) + } } writeGenericType(kotlinType, jvmType, mode) @@ -182,7 +184,7 @@ fun mapType( return type } - else -> throw UnsupportedOperationException("Unknown type " + kotlinType) + else -> throw UnsupportedOperationException("Unknown type $kotlinType") } } @@ -229,7 +231,8 @@ private fun mapBuiltInType( val classId = JavaToKotlinClassMap.mapKotlinToJava(descriptor.fqNameUnsafe) if (classId != null) { if (!mode.kotlinCollectionsToJavaCollections && - JavaToKotlinClassMap.mutabilityMappings.any { it.javaClass == classId }) return null + JavaToKotlinClassMap.mutabilityMappings.any { it.javaClass == classId } + ) return null return typeFactory.createObjectType(JvmClassName.byClassId(classId).internalName) } @@ -269,7 +272,7 @@ fun computeInternalName( } val containerClass = container as? ClassDescriptor - ?: throw IllegalArgumentException("Unexpected container: $container for $klass") + ?: throw IllegalArgumentException("Unexpected container: $container for $klass") val containerInternalName = typeMappingConfiguration.getPredefinedInternalNameForClass(containerClass) ?: computeInternalName( @@ -277,16 +280,15 @@ fun computeInternalName( typeMappingConfiguration, isIrBackend ) - return containerInternalName + "$" + name + return "$containerInternalName$$name" } private fun getContainer(container: DeclarationDescriptor?): DeclarationDescriptor? = - container as? ClassDescriptor ?: container as? PackageFragmentDescriptor ?: - container?.let { getContainer(it.containingDeclaration) } + container as? ClassDescriptor ?: container as? PackageFragmentDescriptor ?: container?.let { getContainer(it.containingDeclaration) } private fun getRepresentativeUpperBound(descriptor: TypeParameterDescriptor): KotlinType { val upperBounds = descriptor.upperBounds - assert(!upperBounds.isEmpty()) { "Upper bounds should not be empty: " + descriptor } + assert(!upperBounds.isEmpty()) { "Upper bounds should not be empty: $descriptor" } return upperBounds.firstOrNull { val classDescriptor = it.constructor.declarationDescriptor as? ClassDescriptor ?: return@firstOrNull false