Roslyn: C# nullable not detecting issue correctly?

Created on 2 Jun 2020  路  1Comment  路  Source: dotnet/roslyn

_This issue has been moved from a ticket on Developer Community._


I'm working on migrating a project to support C# 8.0 nullable but I ran into a situation where it looks like Visual Studio isn't detecting a null value correctly. If you look at the code below in the TestClass constructor the Console.WriteLine method will throw a NullReferenceException because this.Value is null and hasn't been assigned yet. There are no warnings or errors from VS though, it thinks everything is fine here. Am I missing something, shouldn't VS be warning about this? The value is definitely null here. Thanks!

#nullable enable

namespace TestNullable
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            TestClass test = new TestClass("MyString");
        }

        public class TestClass
        {
            private readonly string Value;
            public TestClass(string value)
            {
                System.Console.WriteLine(this.Value.Length.ToString());
                this.Value = value;
            }
        }
    }
}

--- ### Original Comments #### Visual Studio Feedback System on 4/21/2020, 01:46 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Visual Studio Feedback System on 5/28/2020, 08:00 PM:

I have detected that for the last 35 days, this issue didn't have much product team activity and a very small amount of new votes or comments. Based on this, its severity, and affected area, it鈥檚 my experience that this issue is very unlikely to be fixed.


Original Solutions

(no solutions)

Area-Compilers Bug New Language Feature - Nullable Reference Types

Most helpful comment

This will be fixed by #46441

>All comments

This will be fixed by #46441

Was this page helpful?
0 / 5 - 0 ratings