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

Nullability of static field doesn't seem to be tracked #26651

Closed
jcouv opened this issue May 5, 2018 · 3 comments
Closed

Nullability of static field doesn't seem to be tracked #26651

jcouv opened this issue May 5, 2018 · 3 comments

Comments

@jcouv
Copy link
Member

jcouv commented May 5, 2018

Example

public class C 
{
    static readonly string? s = null;
    public void M() 
    {
        if (s != null)
        {
         	s.ToString(); // warning CS8602: Possible dereference of a null reference.
        }
    }
}

Found in nullable dogfood.
Tagging @cston

@jcouv
Copy link
Member Author

jcouv commented May 15, 2018

Here's another symptom, likely from the same cause:

public class C 
{
    static readonly string[] x = new string[] { null }; // no warning
}

@cston
Copy link
Member

cston commented May 15, 2018

The warning is not reported in the second example because we're currently skipping NullableWalker for implicit members. If the initializer is moved to an explicit .cctor, the warning is reported. We should have a separate bug to handle implicit members such as the default .ctor and .cctor.

@cston
Copy link
Member

cston commented Nov 13, 2018

Logged #31139 for the issue with implicit constructors.

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

3 participants