Skip to content

Nullable Reference Types: A warning should be reported when dereferencing a field/property before it is assigned #27016

@PathogenDavid

Description

@PathogenDavid

Version Used: 05/14/18 Nullable Reference Types Preview (csc reports 2.8.0.62830 (e595ee27)) with Visual Studio 15.7.1

Demonstration Code:

public class TestClass
{
    private string x;

    public TestClass()
    {
        Console.WriteLine(x.ToString()); // No warning, CS8602 is expected
        x = "Hello, world!";
    }
}

Expected Behavior:

A warning is reported when x is dereferenced.

Actual Behavior:

There is no compile-time warning and a runtime exception occurs when the code is executed.


Additional info:

The current behavior is the same with a property.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions