dotnet/roslyn

IDE0016 codefix can change behaviour

Ouverte

#36 177 ouverte le 5 juin 2019

 (13 commentaires) (0 réaction) (0 personne assignée)C# (4 257 forks)batch import
Area-AnalyzersBugFeature - IDE0016help wanted

Métriques du dépôt

Stars
 (20 414 étoiles)
Métriques de merge PR
 (Merge moyen 6j 17h) (256 PRs mergées en 30 j)

Description

Version Used: 16.1.1+28922.388

Steps to Reproduce:

object _o;
bool _b;
void M(object o)
{
    if (o == null)
        throw new ArgumentNullException(nameof(o));
    _b = true;
    _o = o;
}

IDE0016 fires and wants to change the code to:

object _o;
bool _b;
void M(object o)
{
    _b = true;
    _o = o ?? throw new ArgumentNullException(nameof(o));
}

Expected Behavior:

No change in behaviour.

Actual Behavior:

Potential change in behaviour due to throw being moved after side effecty code.

Guide contributeur