Skip to content

Should not report warning for second dereference of nullable value #26749

@cston

Description

@cston

The second warning is redundant and incorrect:

class Program
{
    static void F(string? s)
    {
        int n = s.Length; // warning: 's' may be null
        if (s.Length > 0) // warning: 's' may be null
        {
        }
    }
}
(5,17): warning CS8602: Possible dereference of a null reference.
(6,13): warning CS8602: Possible dereference of a null reference.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions