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()),