Properly load top-level constant initializers from multifile classes

Before Kotlin 1.3-M2 we didn't write `has_field` flag for constants
 inside multifile classes. Now we write and rely on this when
 trying to load constant initializers, which is totally fine for
 binaries that were compiled with the 1.3-M2 or newer version.
 Unfortunately, constant initializers will not be loaded for old binaries.

 One way is to avoid relying on this flag, but then we'll get other
 problems (e.g. 3345dc81fd).

 Therefore, for binaries that were compiled with at least 1.3-M2 version,
 we'll rely on the flag, otherwise, we won't.
This commit is contained in:
Mikhail Zarechenskiy
2018-09-16 22:06:21 +03:00
parent 8e66dadb47
commit 7d2bc5c0f6
4 changed files with 26 additions and 11 deletions
@@ -104,14 +104,16 @@ object JvmProtoBufUtil {
fun getJvmFieldSignature(
proto: ProtoBuf.Property,
nameResolver: NameResolver,
typeTable: TypeTable
typeTable: TypeTable,
requireHasFieldFlag: Boolean = true
): JvmMemberSignature.Field? {
val signature = proto.getExtensionOrNull(JvmProtoBuf.propertySignature) ?: return null
val field = if (signature.hasField()) signature.field else return null
val field = if (signature.hasField()) signature.field else null
if (field == null && requireHasFieldFlag) return null
val name = if (field.hasName()) field.name else proto.name
val name = if (field != null && field.hasName()) field.name else proto.name
val desc =
if (field.hasDesc()) nameResolver.getString(field.desc)
if (field != null && field.hasDesc()) nameResolver.getString(field.desc)
else mapTypeDefault(proto.returnType(typeTable), nameResolver) ?: return null
return JvmMemberSignature.Field(nameResolver.getString(name), desc)