Skip to content

Unexpected error for a user-defined conditional logical operator resolution on an interface #78617

@AlekseyTs

Description

@AlekseyTs
public class Program
{
    static void Main()
    {
        C2 x2 = null;
        C2 y2 = null;
        
        // error CS0218: In order for 'C2.operator &(C2, C2)' to be applicable as a short circuit operator,
        //               its declaring type 'C2' must define operator true and operator false
        _ = x2 && y2;
    }
}

interface C1
{
    public static bool operator true(C1 x) => true;
    public static bool operator false(C1 x) => false;
}

interface C2 : C1
{
    public static C2 operator &(C2 x, C2 y) => x;
}

Observed: error CS0218: In order for 'C2.operator &(C2, C2)' to be applicable as a short circuit operator, its declaring type 'C2' must define operator true and operator false

Works if C1 and C2 changed to be classes.

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions