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 13, 2024
1 parent d418c40 commit 02ed123
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<!T>::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()),
Expand Down

0 comments on commit 02ed123

Please sign in to comment.