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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user