Skip to content

Fix TypeRef for generic types #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MetadataProcessor.Shared/Tables/nanoSignaturesTable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Original work from Oleg Rakhmatulin.
Expand Down Expand Up @@ -477,7 +477,7 @@ public void WriteDataType(
if (alsoWriteSubType)
{
GenericInstanceType genericType = (GenericInstanceType)typeDefinition;
WriteDataType(genericType.Resolve(), writer, true, expandEnumType, isTypeDefinition);
WriteDataType(genericType.ElementType, writer, true, expandEnumType, isTypeDefinition);

// OK to use byte here as we won't support more than 0x7F arguments
writer.WriteByte((byte)genericType.GenericArguments.Count);
Expand Down
6 changes: 4 additions & 2 deletions MetadataProcessor.Shared/Tables/nanoTablesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,10 @@ public ushort GetMethodReferenceId(
else if (memberReference is MethodReference &&
MethodReferencesTable.TryGetMethodReferenceId(memberReference as MethodReference, out referenceId))
{
// check if method is external
if (memberReference.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference)
// check if method is external, unless it's a closed generic instance
if (memberReference.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference
&& !(memberReference.DeclaringType is GenericInstanceType genericInstanceType
&& genericInstanceType.HasGenericArguments))
{
// method reference is external
}
Expand Down
12 changes: 6 additions & 6 deletions MetadataProcessor.Shared/nanoAssemblyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,11 +829,6 @@ private HashSet<MetadataToken> BuildDependencyList(MetadataToken token)
set.Add(v.VariableType.GetElementType().MetadataToken);
}
}
else if (v.VariableType.IsValueType
&& !v.VariableType.IsPrimitive)
{
set.Add(v.VariableType.MetadataToken);
}
else if (v.VariableType is GenericInstanceType)
{
// Cecil.Mono has a bug providing TypeSpecs Metadata tokens generic parameters variables, so we need to check against our internal table and build one from it
Expand All @@ -852,6 +847,11 @@ private HashSet<MetadataToken> BuildDependencyList(MetadataToken token)
Debug.Fail($"Couldn't find a TypeSpec entry for {v.VariableType}");
}
}
else if (v.VariableType.IsValueType
&& !v.VariableType.IsPrimitive)
{
set.Add(v.VariableType.MetadataToken);
}
else if (v.VariableType.IsPointer)
{
string message = $"Pointer types in unsafe code aren't supported. Can't use {v.VariableType} variable in \"{md.FullName}\".";
Expand Down Expand Up @@ -1051,7 +1051,7 @@ private HashSet<MetadataToken> BuildDependencyList(MetadataToken token)
{
// add "fabricated" token for TypeSpec using the referenceId as RID
set.Add(new MetadataToken(TokenType.TypeSpec, tsRid));
set.Add(ts.GetElementType().MetadataToken);
set.Add(ts.MetadataToken);
}
else
{
Expand Down