Skip to content

Conversation

IDisposable
Copy link
Contributor

@IDisposable IDisposable commented Aug 1, 2025

Removes the IEquatable constraint from the ThrowIfEqual and ThrowIfNotEqual methods in ArgumentOutOfRangeException.

  • Allows these methods to be used with types that don't implement IEquatable, relying on EqualityComparer.Default.Equals for equality comparisons.
  • This broadens the applicability of these methods without sacrificing functionality.

Resolves #118053

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 1, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@tannergooding
Copy link
Member

This likely needs to wait for .NET 11 since we are locking down for RC1.

However, this is something that I would be willing to take a bar check around given how frequently its been asked for and its a minor change just relaxing a constraint. -- CC. @jeffhandley for secondary input

@IDisposable IDisposable marked this pull request as ready for review August 4, 2025 03:50
@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 03:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the IEquatable<T> constraint from the ThrowIfEqual and ThrowIfNotEqual methods in ArgumentOutOfRangeException, allowing these methods to work with any type rather than just those implementing IEquatable<T>. The methods will continue to use EqualityComparer<T>.Default.Equals for equality comparisons, which provides appropriate equality behavior for all types.

Key changes:

  • Removes generic type constraints from ThrowIfEqual and ThrowIfNotEqual methods
  • Updates corresponding test helper methods to match the new signatures
  • Maintains existing functionality while broadening method applicability

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.CoreLib/src/System/ArgumentOutOfRangeException.cs Removes IEquatable<T> constraint from method signatures
src/libraries/System.Runtime/ref/System.Runtime.cs Updates public API reference to reflect constraint removal
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ArgumentOutOfRangeExceptionTests.cs Updates test helper methods to match new method signatures

@jeffhandley jeffhandley merged commit 2bebc9a into dotnet:main Sep 1, 2025
143 of 146 checks passed
@jeffhandley
Copy link
Member

/backport to release/10.0

I'm supportive of this coming in for 10.0 RC2

Copy link
Contributor

github-actions bot commented Sep 1, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17387958834

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

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Remove IEquatable<T>? constraint on ArgumentOutOfRangeException ThrowIfEqual/ThrowIfNotEqual

4 participants