Skip to content

Commit

Permalink
Update MetadataCodegen.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Nov 18, 2024
1 parent 1b79b58 commit bf23220
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{
Expand Down

0 comments on commit bf23220

Please sign in to comment.