Skip to content

Commit

Permalink
Fix generic signature issue when calling non generic method of closed…
Browse files Browse the repository at this point in the history
… generic type (#96517)

* Fix generic signature issue when calling non generic method of closed generic type

* Apply feedbacks
  • Loading branch information
buyaa-n authored Jan 8, 2024
1 parent ffdb3e4 commit 96851fc
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,9 @@ private EntityHandle GetMemberReferenceHandle(MemberInfo member)
return memberHandle;
}

private EntityHandle GetMethodReference(MethodInfo method, Type[] optionalParameterTypes)
private EntityHandle GetMethodReference(MethodInfo methodInfo, Type[] optionalParameterTypes)
{
MethodInfo method = (MethodInfo)GetOriginalMemberIfConstructedType(methodInfo);
BlobBuilder signature = GetMethodSignature(method, optionalParameterTypes);
KeyValuePair<MethodInfo, BlobBuilder> pair = new(method, signature);
if (!_memberReferences.TryGetValue(pair, out var memberHandle))
Expand All @@ -549,16 +550,28 @@ private EntityHandle GetMethodReference(MethodInfo method, Type[] optionalParame
return memberHandle;
}

private BlobBuilder GetMethodSignature(MethodInfo method, Type[] optionalParameterTypes) =>
private BlobBuilder GetMethodSignature(MethodInfo method, Type[]? optionalParameterTypes) =>
MetadataSignatureHelper.GetMethodSignature(this, ParameterTypes(method.GetParameters()), method.ReturnType,
MethodBuilderImpl.GetSignatureConvention(method.CallingConvention), method.GetGenericArguments().Length, !method.IsStatic, optionalParameterTypes);

private BlobBuilder GetMemberSignature(MemberInfo member)
private static MemberInfo GetOriginalMemberIfConstructedType(MemberInfo memberInfo)
{
Type declaringType = memberInfo.DeclaringType!;
if (declaringType.IsConstructedGenericType && declaringType.GetGenericTypeDefinition() is not TypeBuilderImpl)
{
return declaringType.GetGenericTypeDefinition().GetMemberWithSameMetadataDefinitionAs(memberInfo);
}

return memberInfo;
}

private BlobBuilder GetMemberSignature(MemberInfo memberInfo)
{
MemberInfo member = GetOriginalMemberIfConstructedType(memberInfo);

if (member is MethodInfo method)
{
return MetadataSignatureHelper.GetMethodSignature(this, ParameterTypes(method.GetParameters()), method.ReturnType,
MethodBuilderImpl.GetSignatureConvention(method.CallingConvention), method.GetGenericArguments().Length, !method.IsStatic);
return GetMethodSignature(method, optionalParameterTypes: null);
}

if (member is FieldInfo field)
Expand Down
Loading

0 comments on commit 96851fc

Please sign in to comment.