Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UseExceptionThrowHelpers to only recommend ANE for classes #6314

Merged
merged 2 commits into from
Dec 9, 2022

Conversation

stephentoub
Copy link
Member

I went back and forth on this initially, but decided it makes more sense to be conservative here and only recommend using ArgumentNullException.ThrowIfNull if the type of the parameter is known to be a class. While it could be used for nullable value types or unconstrained generics, both result in boxing that we then rely on the JIT to eliminate.

@stephentoub stephentoub requested a review from a team as a code owner December 9, 2022 17:35
@codecov
Copy link

codecov bot commented Dec 9, 2022

Codecov Report

Merging #6314 (85a4a54) into main (22361ae) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6314   +/-   ##
=======================================
  Coverage   96.07%   96.07%           
=======================================
  Files        1367     1367           
  Lines      315348   315415   +67     
  Branches    10187    10187           
=======================================
+ Hits       302980   303050   +70     
+ Misses       9935     9933    -2     
+ Partials     2433     2432    -1     

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

Consider having tests for constrained type parameters:

using System;

class C
{
    void M1<T>(T arg) where T : class
    {
        if (arg is null) throw new ArgumentNullException(nameof(arg));
    }

    void M2<T>(T arg) where T : IDisposable
    {
        if (arg is null) throw new ArgumentNullException(nameof(arg));
    }

    void M3<T>(T arg) where T : C
    {
        if (arg is null) throw new ArgumentNullException(nameof(arg));
    }
}

@stephentoub stephentoub merged commit 8af25d7 into dotnet:main Dec 9, 2022
@stephentoub stephentoub deleted the anegeneric branch December 9, 2022 23:23
@github-actions github-actions bot added this to the vNext milestone Dec 9, 2022
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.

3 participants