Write underlying property name & type for inline class to metadata

This will be used in the compiler starting from 1.5.20 instead of the
currently used approach of looking for the single value parameter of the
primary constructor. The problem with the current approach is that
primary constructor can be private (since 1.4.30) and the property could
always be private. Relying on private declarations from metadata is
dangerous; for example lazy IR doesn't usually create stubs for private
declarations, and it didn't create stubs for private inline class
constructors before b5f9b1df, which led to the problem reported in
KT-44723.
This commit is contained in:
Alexander Udalov
2021-03-19 22:58:02 +01:00
parent 5baa2e0e7c
commit ea01c97a8e
7 changed files with 909 additions and 194 deletions
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.constants.IntValue
import org.jetbrains.kotlin.resolve.constants.NullValue
import org.jetbrains.kotlin.resolve.constants.StringValue
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.nonSourceAnnotations
import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
import org.jetbrains.kotlin.serialization.deserialization.descriptorVisibility
@@ -150,6 +149,21 @@ class DescriptorSerializer private constructor(
builder.typeTable = typeTableProto
}
classDescriptor.underlyingRepresentation()?.let { parameter ->
builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(parameter.name)
val property = callableMembers.single {
it is PropertyDescriptor && it.extensionReceiverParameter == null && it.name == parameter.name
}
if (!property.visibility.isPublicAPI) {
if (useTypeTable()) {
builder.inlineClassUnderlyingTypeId = typeId(parameter.type)
} else {
builder.setInlineClassUnderlyingType(type(parameter.type))
}
}
}
if (versionRequirementTable == null) error("Version requirements must be serialized for classes: $classDescriptor")
builder.addAllVersionRequirement(versionRequirementTable.serializeVersionRequirements(classDescriptor))