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

Pattern test should inform nullability #26745

Closed
jcouv opened this issue May 9, 2018 · 2 comments
Closed

Pattern test should inform nullability #26745

jcouv opened this issue May 9, 2018 · 2 comments
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented May 9, 2018

There should be no warning in the following, since s is string only matches if s isn't null.

using System;
public class C 
{
    public void M(string? s) 
    {
        if (s is string)
        {
            s.ToString(); // warning CS8602: Possible dereference of a null reference.
        }
    }
}

Conversely, s is null should also inform nullability.
Also, s = null!.

(update: split the null-coalesing issue into separate issue: #26747)

Once fixed, please update this speclet section.

Tagging @cston @gafter

@jcouv jcouv added this to the 16.0 milestone May 9, 2018
@jcouv jcouv changed the title Pattern test should inform nullability Pattern test and null-coalescing should inform nullability May 9, 2018
@jcouv jcouv changed the title Pattern test and null-coalescing should inform nullability Pattern test should inform nullability May 9, 2018
@cston
Copy link
Member

cston commented Jul 9, 2018

See also #26737.

@jcouv
Copy link
Member Author

jcouv commented Jul 9, 2018

Closing this issue as dupe of #26737, and added a note there about s is null scenario.

@jcouv jcouv closed this as completed Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants