Skip to content

Codefix for RCS1244 can change semantics of code #938

@jhinder

Description

@jhinder

Product and Version Used: Roslynator 4.1.1 (in VS 17.3)

Steps to Reproduce:

internal readonly struct C
{
    public static implicit operator C(int i) => new C();
    public static bool operator ==(C left, C right) => default;
    public static bool operator !=(C left, C right) => default;
    public override bool Equals(object? obj) => default;
    public override int GetHashCode() => default;

    void M()
    {
        _ = default(C) == 0; // Compares `C` and `C`
        //         ~~~ RCS1244: Simplify 'default' expression
    }
}

Actual Behavior:
The codefix removes the argument to the default operator, changing the semantics of the expression.

void M()
{
    _ = default == 0; // Compares `int` and `int`
}

Expected Behavior:
The codefix is not offered.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions