SignatureComparer::GetHashCode does not respect flags
Closed this issue · 0 comments
Washi1337 commented
AsmResolver Version
5.2.0
.NET Version
.NET 6.0
Operating System
Windows
Describe the Bug
The SignatureComprer
class can be configured to slightly relax the strict comparisons that are made for assemblies and types. This relaxation is however not reflected in the GetHashCode
implementations. This can result in two members that would be considered equal according to the relaxed rules having two different hashcodes, making it unusable for HashSet<TMember>
and Dictionary<TMember, TValue>
.
How To Reproduce
var comparer = new SignatureComparer(SignatureComparisonFlags.VersionAgnostic);
var reference1 = KnownCorLibs.SystemRuntime_v5_0_0_0;
var reference2 = KnownCorLibs.SystemRuntime_v6_0_0_0;
Assert.Equal(reference1, reference2, comparer);
var set = new HashSet<AssemblyReference>(comparer);
Assert.True(set.Add(reference1));
Assert.False(set.Add(reference2));
Expected Behavior
All checks pass.
Actual Behavior
The last Assert.False
fails.
Additional Context
No response