Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs (C#)

Code before:
    public static C1 operator |(C1 x, C1 y) => x;
    public static bool operator true(C1 x) => false;
    public static bool operator false(C1 x) => false;
}

class Test
{
    void M()
    {
        I1 x = new C1();
        dynamic y = new C1();
        _ = x || y;
    }
}";
            CreateCompilation(source, targetFramework: TargetFramework.Net70).VerifyDiagnostics(
                // (21,13): error CS7083: Expression must be implicitly convertible to Boolean or its type 'I1' must not be an interface and must define operator 'true'.
                //         _ = x || y;
                Diagnostic(ErrorCode.ERR_InvalidDynamicCondition, "x").WithArguments("I1", "true").WithLocation(21, 13)
            );
        }

        [Fact]
        [WorkItem("https://github.com/dotnet/roslyn/issues/80954")]
        public void DynamicBooleanExpression_ClassWithoutOperator()
        {
            // Ensure the class case still works correctly (regression test)
            const string source = @"
class C0 { }

class C1 : C0
{
    public static C1 operator &(C1 x, C1 y) => x;
    public static bool operator true(C1 x) => false;
    public static bool operator false(C1 x) => false;
}

class Test
{
    void M()
    {
        C0 x = new C1();
        dynamic y = new C1();
        _ = x && y;
    }
}";
            CreateCompilation(source, targetFramework: TargetFramework.Net70).VerifyDiagnostics(
                // (17,13): error CS7083: Expression must be implicitly convertible to Boolean or its type 'C0' must not be an interface and must define operator 'false'.
                //         _ = x && y;
                Diagnostic(ErrorCode.ERR_InvalidDynamicCondition, "x").WithArguments("C0", "false").WithLocation(17, 13)
            );
        }

Review comment (suggestion):
I don't think the comment makes the goal of the test clear. Works correctly tends to imply that the code compiles and does something, rather than reporting an error. Consider deleting the comment.
```suggestion
```

Code after:
    public static C1 operator |(C1 x, C1 y) => x;
    public static bool operator true(C1 x) => false;
    public static bool operator false(C1 x) => false;
}

class Test
{
    void M()
    {
        I1 x = new C1();
        dynamic y = new C1();
        _ = x || y;
    }
}";
            CreateCompilation(source, targetFramework: TargetFramework.Net70).VerifyDiagnostics(
                // (21,13): error CS7083: Expression must be implicitly convertible to Boolean or its type 'I1' must not be an interface and must define operator 'true'.
                //         _ = x || y;
                Diagnostic(ErrorCode.ERR_InvalidDynamicCondition, "x").WithArguments("I1", "true").WithLocation(21, 13)
            );
        }

        [Fact]
        [WorkItem("https://github.com/dotnet/roslyn/issues/80954")]
        public void DynamicBooleanExpression_ClassWithoutOperator()
        {
            const string source = @"
class C0 { }

class C1 : C0
{
    public static C1 operator &(C1 x, C1 y) => x;
    public static bool operator true(C1 x) => false;
    public static bool operator false(C1 x) => false;
}

class Test
{
    void M()
    {
        C0 x = new C1();
        dynamic y = new C1();
        _ = x && y;
    }
}";
            CreateCompilation(source, targetFramework: TargetFramework.Net70).VerifyDiagnostics(
                // (17,13): error CS7083: Expression must be implicitly convertible to Boolean or its type 'C0' must not be an interface and must define operator 'false'.
                //         _ = x && y;
                Diagnostic(ErrorCode.ERR_InvalidDynamicCondition, "x").WithArguments("C0", "false").WithLocation(17, 13)
            );
        }