Skip to content

Implement interface fixer doesn't spit out checked keyword for checked user-defined operators #60214

@AlekseyTs

Description

@AlekseyTs
interface I1<T> where T : I1<T>
{
    abstract static T operator checked -(T x);
    abstract static T operator -(T x);

    abstract static T operator checked +(T x, T y);
    abstract static T operator +(T x, T y);

    abstract static explicit operator checked string(T x);
    abstract static explicit operator string(T x);
}

class C1 : I1<C1>
{
}

Use code fixer to implement the interface.

Observed (note none of the operators have checked keyword):

class C1 : I1<C1>
{
    static C1 I1<C1>.operator +(C1 x, C1 y)
    {
        throw new System.NotImplementedException();
    }

    static C1 I1<C1>.operator +(C1 x, C1 y)
    {
        throw new System.NotImplementedException();
    }

    static C1 I1<C1>.operator -(C1 x)
    {
        throw new System.NotImplementedException();
    }

    static C1 I1<C1>.operator -(C1 x)
    {
        throw new System.NotImplementedException();
    }
}

Expected:

class C1 : I1<C1>
{
    static C1 I1<C1>.operator +(C1 x, C1 y)
    {
        throw new System.NotImplementedException();
    }

    static C1 I1<C1>.operator checked +(C1 x, C1 y)
    {
        throw new System.NotImplementedException();
    }

    static C1 I1<C1>.operator -(C1 x)
    {
        throw new System.NotImplementedException();
    }

    static C1 I1<C1>.operator checked -(C1 x)
    {
        throw new System.NotImplementedException();
    }

    static explicit I1<C1>.operator string(C1 x)
    {
        throw new System.NotImplementedException();
    }

    static explicit I1<C1>.operator checked string(C1 x)
    {
        throw new System.NotImplementedException();
    }
}

Similar behavior for an option to implement the interface implicitly.
The fact that conversion operators are not implemented at all is tracked by #60212.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions