From 4f485e27a904d837b467217efbfc0937e5e79875 Mon Sep 17 00:00:00 2001 From: wwh1004 Date: Sat, 28 May 2022 21:47:36 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Importer=20and=20SigComparer=E2=80=98s=20?= =?UTF-8?q?handling=20of=20generic=20when=20must=20treat=20generic=20type?= =?UTF-8?q?=20definition=20as=20generic=20instantiation=20type.=20Mark=20I?= =?UTF-8?q?mporter.ImportDeclaringType(Type)=20as=20obsolete.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DotNet/Importer.cs | 50 +++++++++++---------- src/DotNet/SigComparer.cs | 95 +++++++++++++++++++++------------------ 2 files changed, 78 insertions(+), 67 deletions(-) diff --git a/src/DotNet/Importer.cs b/src/DotNet/Importer.cs index 535d481b4..aa0f02b8f 100644 --- a/src/DotNet/Importer.cs +++ b/src/DotNet/Importer.cs @@ -167,20 +167,19 @@ public Importer(ModuleDef module, ImporterOptions options, GenericParamContext g } /// - /// Imports a as a . If it's a type that should be - /// the declaring type of a field/method reference, call instead. + /// Imports a as a . /// /// The type /// The imported type or null if is invalid public ITypeDefOrRef Import(Type type) => module.UpdateRowId(ImportAsTypeSig(type).ToTypeDefOrRef()); /// - /// Imports a as a . Should be called if it's the - /// declaring type of a method/field reference. See also + /// Imports a as a . See also /// /// The type /// - public ITypeDefOrRef ImportDeclaringType(Type type) => module.UpdateRowId(ImportAsTypeSig(type, type.IsGenericButNotGenericTypeDefinition()).ToTypeDefOrRef()); + [Obsolete("Use 'Import(Type)' instead.")] + public ITypeDefOrRef ImportDeclaringType(Type type) => Import(type); /// /// Imports a as a @@ -197,12 +196,13 @@ public ITypeDefOrRef Import(Type type, IList requiredModifiers, IList /// The type /// The imported type or null if is invalid - public TypeSig ImportAsTypeSig(Type type) => ImportAsTypeSig(type, false); + public TypeSig ImportAsTypeSig(Type type) => ImportAsTypeSig(type, null, false); - TypeSig ImportAsTypeSig(Type type, bool treatAsGenericInst) { + TypeSig ImportAsTypeSig(Type type, Type declaringType, bool? treatAsGenericInst = null) { if (type is null) return null; - switch (treatAsGenericInst ? ElementType.GenericInst : type.GetElementType2()) { + bool treatAsGenericInst2 = treatAsGenericInst ?? declaringType.MustTreatTypeAsGenericInstType(type); + switch (treatAsGenericInst2 ? ElementType.GenericInst : type.GetElementType2()) { case ElementType.Void: return module.CorLibTypes.Void; case ElementType.Boolean: return module.CorLibTypes.Boolean; case ElementType.Char: return module.CorLibTypes.Char; @@ -220,9 +220,9 @@ TypeSig ImportAsTypeSig(Type type, bool treatAsGenericInst) { case ElementType.TypedByRef:return module.CorLibTypes.TypedReference; case ElementType.U: return module.CorLibTypes.UIntPtr; case ElementType.Object: return module.CorLibTypes.Object; - case ElementType.Ptr: return new PtrSig(ImportAsTypeSig(type.GetElementType(), treatAsGenericInst)); - case ElementType.ByRef: return new ByRefSig(ImportAsTypeSig(type.GetElementType(), treatAsGenericInst)); - case ElementType.SZArray: return new SZArraySig(ImportAsTypeSig(type.GetElementType(), treatAsGenericInst)); + case ElementType.Ptr: return new PtrSig(ImportAsTypeSig(type.GetElementType(), declaringType)); + case ElementType.ByRef: return new ByRefSig(ImportAsTypeSig(type.GetElementType(), declaringType)); + case ElementType.SZArray: return new SZArraySig(ImportAsTypeSig(type.GetElementType(), declaringType)); case ElementType.ValueType: return new ValueTypeSig(CreateTypeRef(type)); case ElementType.Class: return new ClassSig(CreateTypeRef(type)); case ElementType.Var: return new GenericVar((uint)type.GenericParameterPosition, gpContext.Type); @@ -237,13 +237,13 @@ TypeSig ImportAsTypeSig(Type type, bool treatAsGenericInst) { var lowerBounds = new int[type.GetArrayRank()]; var sizes = Array2.Empty(); FixSignature = true; - return new ArraySig(ImportAsTypeSig(type.GetElementType(), treatAsGenericInst), (uint)type.GetArrayRank(), sizes, lowerBounds); + return new ArraySig(ImportAsTypeSig(type.GetElementType(), declaringType), (uint)type.GetArrayRank(), sizes, lowerBounds); case ElementType.GenericInst: var typeGenArgs = type.GetGenericArguments(); - var git = new GenericInstSig(ImportAsTypeSig(type.GetGenericTypeDefinition()) as ClassOrValueTypeSig, (uint)typeGenArgs.Length); + var git = new GenericInstSig(ImportAsTypeSig(type.GetGenericTypeDefinition(), null, false) as ClassOrValueTypeSig, (uint)typeGenArgs.Length); foreach (var ga in typeGenArgs) - git.GenericArguments.Add(ImportAsTypeSig(ga)); + git.GenericArguments.Add(ImportAsTypeSig(ga, declaringType)); return git; case ElementType.Sentinel: @@ -393,16 +393,16 @@ IResolutionScope CreateScopeReference(Type type) { /// A list of all optional modifiers or null /// The imported type or null if is invalid public TypeSig ImportAsTypeSig(Type type, IList requiredModifiers, IList optionalModifiers) => - ImportAsTypeSig(type, requiredModifiers, optionalModifiers, false); + ImportAsTypeSig(type, requiredModifiers, optionalModifiers, null); - TypeSig ImportAsTypeSig(Type type, IList requiredModifiers, IList optionalModifiers, bool treatAsGenericInst) { + TypeSig ImportAsTypeSig(Type type, IList requiredModifiers, IList optionalModifiers, Type declaringType) { if (type is null) return null; if (IsEmpty(requiredModifiers) && IsEmpty(optionalModifiers)) - return ImportAsTypeSig(type, treatAsGenericInst); + return ImportAsTypeSig(type, declaringType); FixSignature = true; // Order of modifiers is unknown - var ts = ImportAsTypeSig(type, treatAsGenericInst); + var ts = ImportAsTypeSig(type, declaringType); // We don't know the original order of the modifiers. // Assume all required modifiers are closer to the real type. @@ -469,11 +469,13 @@ IMethod ImportInternal(MethodBase methodBase, bool forceFixSignature) { IMethodDefOrRef method; var origMethod = methodBase.Module.ResolveMethod(methodBase.MetadataToken); if (methodBase.DeclaringType.GetElementType2() == ElementType.GenericInst) - method = module.UpdateRowId(new MemberRefUser(module, methodBase.Name, CreateMethodSig(origMethod), ImportDeclaringType(methodBase.DeclaringType))); + method = module.UpdateRowId(new MemberRefUser(module, methodBase.Name, CreateMethodSig(origMethod), Import(methodBase.DeclaringType))); else method = ImportInternal(origMethod) as IMethodDefOrRef; method = TryResolveMethod(method); + if (methodBase.ContainsGenericParameters) + return method; // Declaring type is instantiated but method itself is not var gim = CreateGenericInstMethodSig(methodBase); var methodSpec = module.UpdateRowId(new MethodSpecUser(method, gim)); @@ -489,7 +491,7 @@ IMethod ImportInternal(MethodBase methodBase, bool forceFixSignature) { parent = GetModuleParent(methodBase.Module); } else - parent = ImportDeclaringType(methodBase.DeclaringType); + parent = Import(methodBase.DeclaringType); if (parent is null) return null; @@ -536,7 +538,7 @@ MethodSig CreateMethodSig(MethodBase mb) { } TypeSig ImportAsTypeSig(ParameterInfo p, Type declaringType) => - ImportAsTypeSig(p.ParameterType, p.GetRequiredCustomModifiers(), p.GetOptionalCustomModifiers(), declaringType.MustTreatTypeAsGenericInstType(p.ParameterType)); + ImportAsTypeSig(p.ParameterType, p.GetRequiredCustomModifiers(), p.GetOptionalCustomModifiers(), declaringType); CallingConvention GetCallingConvention(MethodBase mb) { CallingConvention cc = 0; @@ -627,7 +629,7 @@ public IField Import(FieldInfo fieldInfo, bool forceFixSignature) { parent = GetModuleParent(fieldInfo.Module); } else - parent = ImportDeclaringType(fieldInfo.DeclaringType); + parent = Import(fieldInfo.DeclaringType); if (parent is null) return null; @@ -641,8 +643,8 @@ public IField Import(FieldInfo fieldInfo, bool forceFixSignature) { origField = fieldInfo; } - bool treatAsGenericInst = fieldInfo.DeclaringType.MustTreatTypeAsGenericInstType(origField.FieldType); - var fieldSig = new FieldSig(ImportAsTypeSig(origField.FieldType, origField.GetRequiredCustomModifiers(), origField.GetOptionalCustomModifiers(), treatAsGenericInst)); + var fieldSig = new FieldSig(ImportAsTypeSig(origField.FieldType, + origField.GetRequiredCustomModifiers(), origField.GetOptionalCustomModifiers(), origField.DeclaringType)); var fieldRef = module.UpdateRowId(new MemberRefUser(module, fieldInfo.Name, fieldSig, parent)); var field = TryResolveField(fieldRef); diff --git a/src/DotNet/SigComparer.cs b/src/DotNet/SigComparer.cs index 9c87f7e0b..f9ea2b609 100644 --- a/src/DotNet/SigComparer.cs +++ b/src/DotNet/SigComparer.cs @@ -491,7 +491,7 @@ public enum SigComparerOptions : uint { /// Compares types, signatures, methods, fields, properties, events /// public struct SigComparer { - const SigComparerOptions SigComparerOptions_SubstituteGenericParameters = (SigComparerOptions)0x400; + const SigComparerOptions SigComparerOptions_DontSubstituteGenericParameters = (SigComparerOptions)0x400; const int HASHCODE_MAGIC_GLOBAL_TYPE = 1654396648; const int HASHCODE_MAGIC_NESTED_TYPE = -1049070942; @@ -521,7 +521,7 @@ public struct SigComparer { bool CompareAssemblyLocale => (options & SigComparerOptions.CompareAssemblyLocale) != 0; bool TypeRefCanReferenceGlobalType => (options & SigComparerOptions.TypeRefCanReferenceGlobalType) != 0; bool DontCompareReturnType => (options & SigComparerOptions.DontCompareReturnType) != 0; - bool SubstituteGenericParameters => (options & SigComparerOptions_SubstituteGenericParameters) != 0; + bool DontSubstituteGenericParameters => (options & SigComparerOptions_DontSubstituteGenericParameters) != 0; bool CaseInsensitiveTypeNamespaces => (options & SigComparerOptions.CaseInsensitiveTypeNamespaces) != 0; bool CaseInsensitiveTypeNames => (options & SigComparerOptions.CaseInsensitiveTypeNames) != 0; bool CaseInsensitiveMethodFieldNames => (options & SigComparerOptions.CaseInsensitiveMethodFieldNames) != 0; @@ -2700,7 +2700,7 @@ public int GetHashCode(MemberRef a) { int hash = GetHashCode_MethodFieldName(a.Name); GenericInstSig git; - if (SubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) { + if (!DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) { InitializeGenericArguments(); genericArguments.PushTypeArgs(git.GenericArguments); hash += GetHashCode(a.Signature); @@ -2749,8 +2749,6 @@ public int GetHashCode(MethodSpec a) { if (!recursionCounter.Increment()) return 0; - // We must do this or it won't get the same hash code as some MethodInfos - var oldOptions = SetOptions(SigComparerOptions_SubstituteGenericParameters); var gim = a.GenericInstMethodSig; if (gim is not null) { InitializeGenericArguments(); @@ -2759,7 +2757,6 @@ public int GetHashCode(MethodSpec a) { int hash = GetHashCode(a.Method); if (gim is not null) genericArguments.PopMethodArgs(); - RestoreOptions(oldOptions); recursionCounter.Decrement(); return hash; @@ -3279,11 +3276,11 @@ public bool Equals(TypeSpec a, Type b) { /// Type #1 /// Type #2 /// true if same, false otherwise - public bool Equals(TypeSig a, Type b) => Equals(a, b, false); + public bool Equals(TypeSig a, Type b) => Equals(a, b, null, false); - bool Equals(ITypeDefOrRef a, Type b, bool treatAsGenericInst) { + bool Equals(ITypeDefOrRef a, Type b, Type declaringType) { if (a is TypeSpec ts) - return Equals(ts.TypeSig, b, treatAsGenericInst); + return Equals(ts.TypeSig, b, declaringType); return Equals(a, b); } @@ -3297,7 +3294,7 @@ static bool IsFnPtrElementType(Type a) { var et = a.GetElementType(); if (et is null || et.HasElementType) return false; - if (et != typeof(IntPtr)) // FnPtr is mapped to System.IntPtr + if (et != typeof(IntPtr)) // FnPtr is mapped to System.IntPtr return false; if (!a.FullName.StartsWith("(fnptr)")) return false; @@ -3310,10 +3307,12 @@ static bool IsFnPtrElementType(Type a) { /// /// Type #1 /// Type #2 + /// Root declaring type to check if we should + /// treat as a generic instance type /// true if we should treat /// as a generic instance type /// true if same, false otherwise - bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { + bool Equals(TypeSig a, Type b, Type declaringType, bool? treatAsGenericInst = null) { // Global methods and fields have their DeclaringType set to null. Assume // null always means the global type. if (a is null) @@ -3324,6 +3323,7 @@ bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { return false; bool result; + bool treatAsGenericInst2 = treatAsGenericInst ?? declaringType.MustTreatTypeAsGenericInstType(b); if (genericArguments is not null) a = genericArguments.Resolve(a); @@ -3346,7 +3346,7 @@ bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { case ElementType.I: case ElementType.U: case ElementType.Object: - result = Equals(((TypeDefOrRefSig)a).TypeDefOrRef, b, treatAsGenericInst); + result = Equals(((TypeDefOrRefSig)a).TypeDefOrRef, b, declaringType); break; case ElementType.Ptr: @@ -3357,7 +3357,7 @@ bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { result = a is not null && a.ElementType == ElementType.FnPtr; } else - result = Equals(a.Next, b.GetElementType()); + result = Equals(a.Next, b.GetElementType(), declaringType); break; case ElementType.ByRef: @@ -3368,7 +3368,7 @@ bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { result = a is not null && a.ElementType == ElementType.FnPtr; } else - result = Equals(a.Next, b.GetElementType()); + result = Equals(a.Next, b.GetElementType(), declaringType); break; case ElementType.SZArray: @@ -3379,11 +3379,11 @@ bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { result = a is not null && a.ElementType == ElementType.FnPtr; } else - result = Equals(a.Next, b.GetElementType()); + result = Equals(a.Next, b.GetElementType(), declaringType); break; case ElementType.Pinned: - result = Equals(a.Next, b, treatAsGenericInst); + result = Equals(a.Next, b, declaringType); break; case ElementType.Array: @@ -3394,13 +3394,13 @@ bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { result = ara.Rank == b.GetArrayRank() && (IsFnPtrElementType(b) ? (a = a.Next.RemoveModifiers()) is not null && a.ElementType == ElementType.FnPtr : - Equals(a.Next, b.GetElementType())); + Equals(a.Next, b.GetElementType(), declaringType)); } break; case ElementType.ValueType: case ElementType.Class: - result = Equals((a as ClassOrValueTypeSig).TypeDefOrRef, b, treatAsGenericInst); + result = Equals((a as ClassOrValueTypeSig).TypeDefOrRef, b, declaringType); break; case ElementType.Var: @@ -3416,18 +3416,18 @@ bool Equals(TypeSig a, Type b, bool treatAsGenericInst) { break; case ElementType.GenericInst: - if (!(b.IsGenericType && !b.IsGenericTypeDefinition) && !treatAsGenericInst) { + if (!(b.IsGenericType && !b.IsGenericTypeDefinition) && !treatAsGenericInst2) { result = false; break; } var gia = (GenericInstSig)a; - result = Equals(gia.GenericType, b.GetGenericTypeDefinition()); - result = result && Equals(gia.GenericArguments, b.GetGenericArguments()); + result = Equals(gia.GenericType, b.GetGenericTypeDefinition(), null, false); + result = result && Equals(gia.GenericArguments, b.GetGenericArguments(), declaringType); break; case ElementType.CModReqd: case ElementType.CModOpt: - result = Equals(a.Next, b, treatAsGenericInst); + result = Equals(a.Next, b, declaringType); break; case ElementType.FnPtr: @@ -3518,7 +3518,9 @@ public bool Equals(ExportedType a, Type b) { /// true if we should treat /// as a generic instance type /// The hash code - public int GetHashCode(Type a, bool treatAsGenericInst) { + public int GetHashCode(Type a, bool treatAsGenericInst) => GetHashCode(a, null, treatAsGenericInst); + + int GetHashCode(Type a, Type declaringType, bool? treatAsGenericInst = null) { // ************************************************************************** // IMPORTANT: This hash code must match the TypeSig/TypeDef/TypeRef hash code // ************************************************************************** @@ -3528,7 +3530,8 @@ public int GetHashCode(Type a, bool treatAsGenericInst) { return 0; int hash; - switch (treatAsGenericInst ? ElementType.GenericInst : a.GetElementType2()) { + bool treatAsGenericInst2 = treatAsGenericInst ?? declaringType.MustTreatTypeAsGenericInstType(a); + switch (treatAsGenericInst2 ? ElementType.GenericInst : a.GetElementType2()) { case ElementType.Void: case ElementType.Boolean: case ElementType.Char: @@ -3562,30 +3565,30 @@ public int GetHashCode(Type a, bool treatAsGenericInst) { case ElementType.Ptr: hash = HASHCODE_MAGIC_ET_PTR + - (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType())); + (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType(), declaringType)); break; case ElementType.ByRef: hash = HASHCODE_MAGIC_ET_BYREF + - (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType())); + (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType(), declaringType)); break; case ElementType.SZArray: hash = HASHCODE_MAGIC_ET_SZARRAY + - (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType())); + (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType(), declaringType)); break; case ElementType.CModReqd: case ElementType.CModOpt: case ElementType.Pinned: - hash = GetHashCode(a.GetElementType()); + hash = GetHashCode(a.GetElementType(), declaringType); break; case ElementType.Array: // The type doesn't store sizes and lower bounds, so can't use them to // create the hash hash = HASHCODE_MAGIC_ET_ARRAY + a.GetArrayRank() + - (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType())); + (IsFnPtrElementType(a) ? GetHashCode_FnPtr_SystemIntPtr() : GetHashCode(a.GetElementType(), declaringType)); break; case ElementType.Var: @@ -3597,7 +3600,8 @@ public int GetHashCode(Type a, bool treatAsGenericInst) { break; case ElementType.GenericInst: - hash = HASHCODE_MAGIC_ET_GENERICINST + GetHashCode(a.GetGenericTypeDefinition()) + GetHashCode(a.GetGenericArguments()); + hash = HASHCODE_MAGIC_ET_GENERICINST + GetHashCode(a.GetGenericTypeDefinition(), false) + + GetHashCode(a.GetGenericArguments(), declaringType); break; case ElementType.ValueArray: @@ -3618,8 +3622,10 @@ public int GetHashCode(Type a, bool treatAsGenericInst) { /// Gets the hash code of a type list /// /// The type list + /// Root declaring type to check if we should + /// treat as a generic instance type /// The hash code - int GetHashCode(IList a) { + int GetHashCode(IList a, Type declaringType) { //************************************************************************ // IMPORTANT: This code must match any other GetHashCode(IList) //************************************************************************ @@ -3629,7 +3635,7 @@ int GetHashCode(IList a) { return 0; uint hash = 0; for (int i = 0; i < a.Count; i++) { - hash += (uint)GetHashCode(a[i]); + hash += (uint)GetHashCode(a[i], declaringType); hash = (hash << 13) | (hash >> 19); } recursionCounter.Decrement(); @@ -3684,8 +3690,10 @@ public int GetHashCode_TypeDef(Type a) { /// /// Type list #1 /// Type list #2 + /// Root declaring type to check if we should + /// treat as a generic instance type /// true if same, false otherwise - bool Equals(IList a, IList b) { + bool Equals(IList a, IList b, Type declaringType) { if ((object)a == (object)b) return true; // both are null if (a is null || b is null) @@ -3699,7 +3707,7 @@ bool Equals(IList a, IList b) { else { int i; for (i = 0; i < a.Count; i++) { - if (!Equals(a[i], b[i])) + if (!Equals(a[i], b[i], declaringType)) break; } result = i == a.Count; @@ -4006,6 +4014,7 @@ public bool Equals(MemberRef a, MethodBase b) { result = a.IsMethodRef && a.MethodSig.Generic; var oldOptions = ClearOptions(SigComparerOptions.CompareMethodFieldDeclaringType); + SetOptions(SigComparerOptions_DontSubstituteGenericParameters); result = result && Equals(a, b.Module.ResolveMethod(b.MetadataToken)); RestoreOptions(oldOptions); result = result && DeclaringTypeEquals(a, b); @@ -4020,7 +4029,7 @@ amSig is not null && (!amSig.Generic && !b.IsGenericMethodDefinition && !b.IsGenericMethod)); GenericInstSig git; - if (SubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) { + if (!DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) { InitializeGenericArguments(); genericArguments.PushTypeArgs(git.GenericArguments); result = result && Equals(amSig, b); @@ -4115,12 +4124,13 @@ public bool Equals(MethodSpec a, MethodBase b) { // declaring type (its declaring type is a generic type def). // NOTE: We must not push generic method args when comparing a.Method var oldOptions = ClearOptions(SigComparerOptions.CompareMethodFieldDeclaringType); + SetOptions(SigComparerOptions_DontSubstituteGenericParameters); result = result && Equals(a.Method, b.Module.ResolveMethod(b.MetadataToken)); RestoreOptions(oldOptions); result = result && DeclaringTypeEquals(a.Method, b); var gim = a.GenericInstMethodSig; - result = result && gim is not null && Equals(gim.GenericArguments, b.GetGenericArguments()); + result = result && gim is not null && Equals(gim.GenericArguments, b.GetGenericArguments(), b.DeclaringType); recursionCounter.Decrement(); return result; @@ -4197,8 +4207,7 @@ int GetHashCode_ReturnType(MethodBase a) { return GetHashCode(typeof(void)); } - int GetHashCode(ParameterInfo a, Type declaringType) => GetHashCode(a.ParameterType, declaringType.MustTreatTypeAsGenericInstType(a.ParameterType)); - int GetHashCode(Type a, Type declaringType) => GetHashCode(a, declaringType.MustTreatTypeAsGenericInstType(a)); + int GetHashCode(ParameterInfo a, Type declaringType) => GetHashCode(a.ParameterType, declaringType); /// /// Compares calling conventions @@ -4329,7 +4338,7 @@ bool Equals(TypeSig a, ParameterInfo b, Type declaringType) { return false; bool result = ModifiersEquals(a, b.GetRequiredCustomModifiers(), b.GetOptionalCustomModifiers(), out var a2) && - Equals(a2, b.ParameterType, declaringType.MustTreatTypeAsGenericInstType(b.ParameterType)); + Equals(a2, b.ParameterType, declaringType); recursionCounter.Decrement(); return result; @@ -4470,7 +4479,7 @@ bool Equals(FieldSig a, FieldInfo b) { return false; bool result = ModifiersEquals(a.Type, b.GetRequiredCustomModifiers(), b.GetOptionalCustomModifiers(), out var a2) && - Equals(a2, b.FieldType, b.DeclaringType.MustTreatTypeAsGenericInstType(b.FieldType)); + Equals(a2, b.FieldType, b.DeclaringType); recursionCounter.Decrement(); return result; @@ -4501,7 +4510,7 @@ public bool Equals(MemberRef a, FieldInfo b) { bool result = Equals_MethodFieldNames(a.Name, b.Name); GenericInstSig git; - if (SubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) { + if (!DontSubstituteGenericParameters && (git = GetGenericInstanceType(a.Class)) is not null) { InitializeGenericArguments(); genericArguments.PushTypeArgs(git.GenericArguments); result = result && Equals(a.FieldSig, b); @@ -4583,7 +4592,7 @@ bool Equals(PropertySig a, PropertyInfo b) { return false; bool result = ModifiersEquals(a.RetType, b.GetRequiredCustomModifiers(), b.GetOptionalCustomModifiers(), out var a2) && - Equals(a2, b.PropertyType, b.DeclaringType.MustTreatTypeAsGenericInstType(b.PropertyType)); + Equals(a2, b.PropertyType, b.DeclaringType); recursionCounter.Decrement(); return result; @@ -4627,7 +4636,7 @@ public bool Equals(EventDef a, EventInfo b) { return false; bool result = Equals_EventNames(a.Name, b.Name) && - Equals(a.EventType, b.EventHandlerType, b.DeclaringType.MustTreatTypeAsGenericInstType(b.EventHandlerType)) && + Equals(a.EventType, b.EventHandlerType, b.DeclaringType) && (!CompareEventDeclaringType || Equals(a.DeclaringType, b.DeclaringType)); recursionCounter.Decrement();