Support serialization of built-in ranges as error types
This will be needed to move ranges and progressions out of builtins. Currently they're only used in signatures of "rangeTo" functions on primitives
This commit is contained in:
+21
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TypeProjection> = 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<TypeProjection>,
|
||||
isMarkedNullable: Boolean
|
||||
) : ErrorType(constructor, memberScope, arguments, isMarkedNullable) {
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
|
||||
UnresolvedType(presentableName, constructor, memberScope, arguments, newNullability)
|
||||
}
|
||||
|
||||
@@ -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<TypeProjection> 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);
|
||||
|
||||
Reference in New Issue
Block a user