Improve hack in BuiltInsSerializerExtension for ranges

Serialize class names as qualified names in the string table, not as
simple strings. Otherwise NameResolverImpl crashes on deserialization
because it expects that all class names are indices into QualifiedName
table
This commit is contained in:
Alexander Udalov
2017-05-17 16:06:08 +03:00
parent 6d47991172
commit 7f73e9f4f7
3 changed files with 21 additions and 26 deletions
@@ -17,17 +17,19 @@
package org.jetbrains.kotlin.serialization.builtins
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
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"
)
private val shortNameToClassId = mapOf(
"IntRange" to "kotlin.ranges.IntRange",
"LongRange" to "kotlin.ranges.LongRange",
"CharRange" to "kotlin.ranges.CharRange"
).mapValues { (_, value) -> ClassId.topLevel(FqName(value)) }
override fun shouldUseTypeTable(): Boolean = true
@@ -37,9 +39,9 @@ class BuiltInsSerializerExtension : KotlinSerializerExtensionBase(BuiltInSeriali
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")
val classId = shortNameToClassId[unwrapped.presentableName]
?: throw UnsupportedOperationException("Unsupported unresolved type: $unwrapped")
builder.className = stringTable.getStringIndex(fullName)
builder.className = stringTable.getClassIdIndex(classId)
}
}