From 02ed12352b806e4b77d3406145bc06d2b3460627 Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Wed, 13 Nov 2024 10:56:54 +0100 Subject: [PATCH] Update MetadataCodegen.cs --- .../Internal/Codegen/MetadataCodegen.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs b/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs index ce8c39862..d25f66ae5 100644 --- a/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs +++ b/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs @@ -305,6 +305,35 @@ Symbol GetContainingSymbol() case FieldSymbol field: { + // TODO: Hack, is there some more general way to deal with this? + // Problem is that we need to generic instantiate the parent of the field reference... + // Otherwise the field ref will look Package::Type::field instead of Package::Type::field + if (field.ContainingSymbol is SourceClassSymbol { IsGenericDefinition: true } sourceClass) + { + var parentGeneric = this.GetEntityHandle(sourceClass); + var parentInstance = this.EncodeBlob(e => + { + var argsEncoder = e + .TypeSpecificationSignature() + .GenericInstantiation( + genericType: parentGeneric, + genericArgumentCount: sourceClass.GenericParameters.Length, + isValueType: sourceClass.IsValueType); + foreach (var param in sourceClass.GenericParameters) + { + this.EncodeSignatureType(argsEncoder.AddArgument(), param); + } + }); + return this.AddMemberReference( + parent: this.MetadataBuilder.AddTypeSpecification(parentInstance), + name: field.Name, + signature: this.EncodeBlob(e => + { + var encoder = e.Field(); + this.EncodeSignatureType(encoder.Type(), field.Type); + })); + } + return this.AddMemberReference( parent: this.GetEntityHandle(field.ContainingSymbol ?? throw new InvalidOperationException()),