Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cston opened this issue Dec 18, 2018 · 0 comments
Closed

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

cston opened this issue Dec 18, 2018 · 0 comments
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug New Language Feature - Nullable Reference Types Nullable Reference Types
Milestone

Comments

@cston
Copy link
Member

cston commented Dec 18, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug New Language Feature - Nullable Reference Types Nullable Reference Types
Projects
None yet
Development

No branches or pull requests

4 participants