dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.1k stars 4.04k forks source link

Inconsistent nullable warning behavior involving the null-forgiving operator on the left-hand-side #75997

Open gafter opened 5 days ago

gafter commented 5 days ago

There is inconsistent design around nullable diagnostics, illustrated below.

class C
{
    void M(
        ref object o,
        ref object p)
    {
        // error CS8598
        (o!) = null;

        // warning CS8600, despite ! operator
        (o!, p!) = (1, null);

        // no warning
        (o!, p!) = this;

        // no warning
        // Deconstruct(out o!, out p!);
    }

    void Deconstruct(
        out object? o,
        out object? p)
    {
        o = null;
        p = null;
    }
}