diff --git a/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt b/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt index 1b984dbf6fb..338b57e3159 100644 --- a/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt +++ b/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt @@ -18,7 +18,28 @@ package org.jetbrains.kotlin.serialization.builtins import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase +import org.jetbrains.kotlin.serialization.ProtoBuf +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.UnresolvedType class BuiltInsSerializerExtension : KotlinSerializerExtensionBase(BuiltInSerializerProtocol) { + private val shortNameToFullName = mapOf( + "IntRange" to "kotlin/ranges/IntRange", + "LongRange" to "kotlin/ranges/LongRange", + "CharRange" to "kotlin/ranges/CharRange" + ) + override fun shouldUseTypeTable(): Boolean = true + + override fun serializeErrorType(type: KotlinType, builder: ProtoBuf.Type.Builder) { + val unwrapped = type.unwrap() + if (unwrapped !is UnresolvedType) { + throw UnsupportedOperationException("Error types which are not UnresolvedType instances are not supported here: $unwrapped") + } + + val fullName = shortNameToFullName[unwrapped.presentableName] + ?: throw UnsupportedOperationException("Unsupported unresolved type: $unwrapped") + + builder.className = stringTable.getStringIndex(fullName) + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index f4789ff5273..039b906da3e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -222,7 +222,7 @@ class TypeResolver( val arguments = resolveTypeProjections( c, ErrorUtils.createErrorType("No type").constructor, qualifierResolutionResult.allProjections ) - result = type(ErrorUtils.createErrorTypeWithArguments(type.getDebugText(), arguments)) + result = type(ErrorUtils.createUnresolvedType(type.getDebugText(), arguments)) return } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt index 3aa8ecbea74..487f3e5423e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.types import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.resolve.scopes.MemberScope -class ErrorType @JvmOverloads internal constructor( +open class ErrorType @JvmOverloads internal constructor( override val constructor: TypeConstructor, override val memberScope: MemberScope, override val arguments: List = emptyList(), @@ -36,3 +36,14 @@ class ErrorType @JvmOverloads internal constructor( override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = ErrorType(constructor, memberScope, arguments, newNullability) } + +class UnresolvedType( + val presentableName: String, + constructor: TypeConstructor, + memberScope: MemberScope, + arguments: List, + isMarkedNullable: Boolean +) : ErrorType(constructor, memberScope, arguments, isMarkedNullable) { + override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = + UnresolvedType(presentableName, constructor, memberScope, arguments, newNullability) +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index e69b38bcf43..cf6f3d63d15 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -411,6 +411,12 @@ public class ErrorUtils { return new ErrorType(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments, false); } + @NotNull + public static SimpleType createUnresolvedType(@NotNull String presentableName, @NotNull List arguments) { + return new UnresolvedType(presentableName, createErrorTypeConstructor(presentableName), createErrorScope(presentableName), + arguments, false); + } + @NotNull public static TypeConstructor createErrorTypeConstructor(@NotNull String debugMessage) { return createErrorTypeConstructorWithCustomDebugName("[ERROR : " + debugMessage + "]", ERROR_CLASS);