Skip to content
Merged
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
22 changes: 19 additions & 3 deletions src/DotNet/SigComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,7 @@ public int GetHashCode(MemberRef a) {

int hash = GetHashCode_MethodFieldName(a.Name);
GenericInstSig git;
if (!DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) {
if (CompareMethodFieldDeclaringType && !DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) {
InitializeGenericArguments();
genericArguments.PushTypeArgs(git.GenericArguments);
hash += GetHashCode(a.Signature);
Expand Down Expand Up @@ -3974,6 +3974,12 @@ public bool Equals(MethodSig a, MethodBase b) {
if (!recursionCounter.Increment())
return false;

if (!CompareMethodFieldDeclaringType && b.DeclaringType.IsGenericButNotGenericTypeDefinition()) {
var t = b;
b = b.Module.ResolveMethod(b.MetadataToken);
if (b.IsGenericButNotGenericMethodDefinition())
b = ((MethodInfo)b).MakeGenericMethod(t.GetGenericArguments());
}
bool result = Equals(a.GetCallingConvention(), b) &&
(DontCompareReturnType || ReturnTypeEquals(a.RetType, b)) &&
Equals(a.Params, b.GetParameters(), b.DeclaringType) &&
Expand Down Expand Up @@ -4029,7 +4035,7 @@ amSig is not null &&
(!amSig.Generic && !b.IsGenericMethodDefinition && !b.IsGenericMethod));

GenericInstSig git;
if (!DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) {
if (CompareMethodFieldDeclaringType && !DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) {
InitializeGenericArguments();
genericArguments.PushTypeArgs(git.GenericArguments);
result = result && Equals(amSig, b);
Expand Down Expand Up @@ -4166,6 +4172,12 @@ int GetHashCode_MethodSig(MethodBase a) {
return 0;
int hash;

if (!CompareMethodFieldDeclaringType && a.DeclaringType.IsGenericButNotGenericTypeDefinition()) {
var t = a;
a = a.Module.ResolveMethod(a.MetadataToken);
if (t.IsGenericButNotGenericMethodDefinition())
a = ((MethodInfo)a).MakeGenericMethod(t.GetGenericArguments());
}
hash = GetHashCode_CallingConvention(a.CallingConvention, a.IsGenericMethod) +
GetHashCode(a.GetParameters(), a.DeclaringType);
if (!DontCompareReturnType)
Expand Down Expand Up @@ -4478,6 +4490,8 @@ bool Equals(FieldSig a, FieldInfo b) {
if (!recursionCounter.Increment())
return false;

if (!CompareMethodFieldDeclaringType && b.DeclaringType.IsGenericButNotGenericTypeDefinition())
b = b.Module.ResolveField(b.MetadataToken);
bool result = ModifiersEquals(a.Type, b.GetRequiredCustomModifiers(), b.GetOptionalCustomModifiers(), out var a2) &&
Equals(a2, b.FieldType, b.DeclaringType);

Expand Down Expand Up @@ -4510,7 +4524,7 @@ public bool Equals(MemberRef a, FieldInfo b) {
bool result = Equals_MethodFieldNames(a.Name, b.Name);

GenericInstSig git;
if (!DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) {
if (CompareMethodFieldDeclaringType && !DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) {
InitializeGenericArguments();
genericArguments.PushTypeArgs(git.GenericArguments);
result = result && Equals(a.FieldSig, b);
Expand Down Expand Up @@ -4555,6 +4569,8 @@ int GetHashCode_FieldSig(FieldInfo a) {
return 0;
int hash;

if (!CompareMethodFieldDeclaringType && a.DeclaringType.IsGenericButNotGenericTypeDefinition())
a = a.Module.ResolveField(a.MetadataToken);
hash = GetHashCode_CallingConvention(0, false) + GetHashCode(a.FieldType, a.DeclaringType);

recursionCounter.Decrement();
Expand Down