Skip to content

Commit e3cbd3f

Browse files
committed
Fix ImmutableHashSet.SetEquals to respect KeyComparer for correctness
1 parent 4ff20e6 commit e3cbd3f

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -743,25 +743,23 @@ private static bool SetEquals(IEnumerable<T> other, MutationInput origin)
743743
switch (other)
744744
{
745745
case ImmutableHashSet<T> otherAsImmutableHashSet:
746-
if (otherAsImmutableHashSet.Count != origin.Count)
747-
{
748-
return false;
749-
}
750-
751746
if (EqualityComparer<IEqualityComparer<T>>.Default.Equals(origin.EqualityComparer, otherAsImmutableHashSet.KeyComparer))
752747
{
748+
if (otherAsImmutableHashSet.Count != origin.Count)
749+
{
750+
return false;
751+
}
753752
return SetEqualsWithImmutableHashset(otherAsImmutableHashSet, origin);
754753
}
755754
break;
756755

757756
case HashSet<T> otherAsHashset:
758-
if (otherAsHashset.Count != origin.Count)
759-
{
760-
return false;
761-
}
762-
763757
if (EqualityComparer<IEqualityComparer<T>>.Default.Equals(origin.EqualityComparer, otherAsHashset.Comparer))
764758
{
759+
if (otherAsHashset.Count != origin.Count)
760+
{
761+
return false;
762+
}
765763
return SetEqualsWithHashset(otherAsHashset, origin);
766764
}
767765
break;

0 commit comments

Comments
 (0)