dotnet/roslyn

Error message on `!Main` should be refined

オープン

#19,948 opened on 2017/06/01

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (PR metrics pending)

説明

We could add a new diagnostic to improve clarity: error CS0023: Operator '!' cannot be applied to operand of type 'method group'

        [Fact]
        public void NegationUnaryOperatorOnTypelessExpressions()
        {
            string source = @"
class C
{
    static void Main()
    {
        if (!Main || !null)
        {
        }
    }
}";
            var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular7_1, options: TestOptions.DebugExe);
            comp.VerifyDiagnostics(
                // (6,13): error CS0023: Operator '!' cannot be applied to operand of type 'method group'
                //         if (!Main || !null)
                Diagnostic(ErrorCode.ERR_BadUnaryOp, "!Main").WithArguments("!", "method group").WithLocation(6, 13),
                // (6,22): error CS8310: Operator '!' cannot be applied to operand '<null>'
                //         if (!Main || !null)
                Diagnostic(ErrorCode.ERR_BadOpOnNullOrDefault, "!null").WithArguments("!", "<null>").WithLocation(6, 22)
                );
        }

Relates to discussion https://github.com/dotnet/roslyn/pull/19870#discussion_r119425836

コントリビューターガイド