From bf23220b1a1302a5235419dfb2d74b354f06e0f2 Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Mon, 18 Nov 2024 21:36:56 +0100 Subject: [PATCH] Update MetadataCodegen.cs --- .../Internal/Codegen/MetadataCodegen.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs b/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs index e013bcb26..0491ce61d 100644 --- a/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs +++ b/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs @@ -309,9 +309,25 @@ Symbol GetContainingSymbol() case FieldSymbol field: { + var parentHandle = this.GetEntityHandle(field.ContainingSymbol ?? throw new InvalidOperationException()); + // NOTE: Hack for field definitions for generics + if (field.ContainingSymbol is SourceClassSymbol { IsGenericDefinition: true } sourceClass) + { + var genericInstance = this.EncodeBlob(e => + { + var argsEncoder = e.TypeSpecificationSignature().GenericInstantiation( + genericType: parentHandle, + genericArgumentCount: sourceClass.GenericParameters.Length, + isValueType: sourceClass.IsValueType); + foreach (var param in sourceClass.GenericParameters) + { + this.EncodeSignatureType(argsEncoder.AddArgument(), param); + } + }); + parentHandle = this.MetadataBuilder.AddTypeSpecification(genericInstance); + } return this.AddMemberReference( - parent: this.GetEntityHandle(field.ContainingSymbol - ?? throw new InvalidOperationException()), + parent: parentHandle, name: field.Name, signature: this.EncodeBlob(e => {