Skip to content

Conversation

@thomhurst
Copy link
Owner

Fixes #4406

@thomhurst
Copy link
Owner Author

Summary

This PR fixes ambiguous overload resolution for types implementing both mutable and read-only collection interfaces (e.g., ImmutableHashSet) by adjusting overload resolution priorities.

Critical Issues

None found ✅

Suggestions

None - the fix is minimal, targeted, and includes a proper regression test.

Analysis

The PR resolves the compilation error reported in #4406 by adjusting OverloadResolutionPriority attributes to break ambiguity:

For Sets:

  • ISet<T>: priority 2 → 3
  • IReadOnlySet<T>: stays at priority 2

For Dictionaries (preventive fix):

  • IDictionary<TKey, TValue>: priority 2 → 3
  • IReadOnlyDictionary<TKey, TValue>: priority 3 → 2

This makes mutable interfaces (priority 3) preferred over read-only interfaces (priority 2) when types implement both, which is consistent and reasonable since mutable interfaces are more specific.

Both SetAssertion<T> and ReadOnlySetAssertion<T> provide identical functionality through their adapters, so choosing either interface produces the same assertion behavior. The test case properly validates the fix using the exact reproduction from the issue.

Verdict

APPROVE - No critical issues

@thomhurst
Copy link
Owner Author

Summary

Fixes compilation error for types implementing both IReadOnlySet and ISet (like ImmutableHashSet) by adjusting overload resolution priorities.

Critical Issues

None found ✅

Analysis

The PR correctly addresses issue #4406 by adjusting OverloadResolutionPriority attributes:

  • ISet: Priority 2 → 3 (now preferred over IReadOnlySet)
  • IDictionary: Priority 2 → 3 (now preferred over IReadOnlyDictionary)
  • IReadOnlyDictionary: Priority 3 → 2

This ensures that when a type implements both interfaces (like ImmutableHashSet or ImmutableDictionary<K,V>), the more specific mutable interface overload is chosen, resolving the ambiguity.

The changes follow TUnit rules:

  • ✅ PublicAPI snapshots updated correctly (.verified.txt files)
  • ✅ Test case added to verify the fix
  • ✅ No performance concerns (not a hot path)

Verdict

APPROVE - No critical issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Compilation error on set types that implement both IReadonlySet and ISet

2 participants