Skip to content

Infer nullability of receiver from ?. expression compared with non-null #31906

@cston

Description

@cston

Currently reporting a warning for second s.ToString();

class Program
{
    static void F(string? s)
    {
        if (s?.Length != null)
            s.ToString();

        if (s?.Length == 1)
            s.ToString(); // warning: may be null
    }
}

[jcouv update:] relates to #27928 (nullability analysis of ==). If we learn that x == 1 means that x is non-null, then the above behavior should fall out.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions