Skip to content

null flow state should be shown at declaration site as well as use site #42897

@YairHalberstadt

Description

@YairHalberstadt

Version Used: VS 16.6 preview 1

Steps to Reproduce:

In VS copy the following:

#nullable enable
public class C
{
    string M()
    {
        var str = "hello";
        return str;
    }
}

Hover over str in return str.

You get the following popup:

image

Hover over str in var str = "hello";

You get the following popup:

image

Note it doesn't mention the null flow state, only the null-type of the variable.

I found this extremely confusing since str is very clearly not null. I wasted a few minutes trying to find out if the method I was calling returned null, before I realized it was because var is always inferred as nullable.

I think this would be less confusing if the null flow state was also shown in declaration so it would say:

(local variable) string? str
str is not null here"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Complete

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions