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.06k stars 4.04k forks source link

DoesNotReturnIf incorrectly handled #38124

Closed ufcpp closed 5 years ago

ufcpp commented 5 years ago

Version Used:

VS 16.3.0 Preview 2.0

Steps to Reproduce:

static void M1(string? s)
{
    Debug.Assert(s != null);
    Console.WriteLine(s.Length); // no warning
}

static void M2(string? s)
{
    Debug.Assert(false);
    Console.WriteLine(s.Length); // CS8602
}

Expected Behavior:

Both M1 and M2 have no warning.

Actual Behavior:

M2 produces CS8602 warning.

agocke commented 5 years ago

What target framework?

ufcpp commented 5 years ago

netcoreapp3.0

The Debug class is in

Assembly System.Diagnostics.Debug, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a // C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.0.0-preview8-28405-07\ref\netcoreapp3.0\System.Diagnostics.Debug.dll

and its signature is

        [Conditional("DEBUG")]
        public static void Assert([DoesNotReturnIf(false)] bool condition)
        {
        }
RikkiGibson commented 5 years ago

Looks like the fix was merged, so will close this issue. Thanks for reporting it @ufcpp.