Fix metadata deserialization for context receivers with type table
In DeserializedClassDescriptor and MemberDeserializer, only the `contextReceiverTypeList` field was used, and not `contextReceiverTypeIdList` which is used when `-Xuse-type-table` is enabled. The convention is to use a bunch of utilities declared in `protoTypeTableUtil.kt` which deal with both methods of reading types. Also, simplify the deserialization code in FIR (which was correct for some reason).
This commit is contained in:
+18
@@ -998,6 +998,24 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadJava/compiledKotlin/contextReceivers")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ContextReceivers extends AbstractJvmRuntimeDescriptorLoaderTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInContextReceivers() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/contextReceivers"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleContextReceivers.kt")
|
||||
public void testSimpleContextReceivers() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/contextReceivers/SimpleContextReceivers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadJava/compiledKotlin/coroutines")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
proto.receiverType(c.typeTable)?.let(local.typeDeserializer::type)?.let { receiverType ->
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(property, receiverType, receiverAnnotations)
|
||||
},
|
||||
proto.contextReceiverTypeList.map { it.toContextReceiver(local, property) }
|
||||
proto.contextReceiverTypes(c.typeTable).map { it.toContextReceiver(local, property) }
|
||||
)
|
||||
|
||||
// Per documentation on Property.getter_flags in metadata.proto, if an accessor flags field is absent, its value should be computed
|
||||
@@ -212,7 +212,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(function, receiverType, receiverAnnotations)
|
||||
},
|
||||
getDispatchReceiverParameter(),
|
||||
proto.contextReceiverTypeList.mapNotNull { it.toContextReceiver(local, function) },
|
||||
proto.contextReceiverTypes(c.typeTable).mapNotNull { it.toContextReceiver(local, function) },
|
||||
local.typeDeserializer.ownTypeParameters,
|
||||
local.memberDeserializer.valueParameters(proto.valueParameterList, proto, AnnotatedCallableKind.FUNCTION),
|
||||
local.typeDeserializer.type(proto.returnType(c.typeTable)),
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ class DeserializedClassDescriptor(
|
||||
|
||||
override fun getConstructors() = constructors()
|
||||
|
||||
override fun getContextReceivers(): List<ReceiverParameterDescriptor> = classProto.contextReceiverTypeList.map {
|
||||
override fun getContextReceivers(): List<ReceiverParameterDescriptor> = classProto.contextReceiverTypes(c.typeTable).map {
|
||||
val contextReceiverType = c.typeDeserializer.type(it)
|
||||
ReceiverParameterDescriptorImpl(
|
||||
thisAsReceiverParameter,
|
||||
|
||||
@@ -113,3 +113,12 @@ fun ProtoBuf.Expression.isInstanceType(typeTable: TypeTable): ProtoBuf.Type? = w
|
||||
hasIsInstanceTypeId() -> typeTable[isInstanceTypeId]
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun ProtoBuf.Class.contextReceiverTypes(typeTable: TypeTable): List<ProtoBuf.Type> =
|
||||
contextReceiverTypeList.takeIf(Collection<*>::isNotEmpty) ?: contextReceiverTypeIdList.map { typeTable[it] }
|
||||
|
||||
fun ProtoBuf.Function.contextReceiverTypes(typeTable: TypeTable): List<ProtoBuf.Type> =
|
||||
contextReceiverTypeList.takeIf(Collection<*>::isNotEmpty) ?: contextReceiverTypeIdList.map { typeTable[it] }
|
||||
|
||||
fun ProtoBuf.Property.contextReceiverTypes(typeTable: TypeTable): List<ProtoBuf.Type> =
|
||||
contextReceiverTypeList.takeIf(Collection<*>::isNotEmpty) ?: contextReceiverTypeIdList.map { typeTable[it] }
|
||||
|
||||
Reference in New Issue
Block a user