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

Null state in unreachable code #32047

Closed
gafter opened this issue Dec 28, 2018 · 1 comment
Closed

Null state in unreachable code #32047

gafter opened this issue Dec 28, 2018 · 1 comment
Assignees
Labels
Area-Compilers Area-Language Design Need Design Review The end user experience design needs to be reviewed and approved. New Language Feature - Nullable Reference Types Nullable Reference Types
Milestone

Comments

@gafter
Copy link
Member

gafter commented Dec 28, 2018

I think the null state of an expression should take into account when it occurs in unreachable code. An expression in unreachable code is never ever null. Even the expression null is never null in unreachable code.

This is not the same as simply suppressing warnings in unreachable code (though we should consider that too). For example:

#nullable enable
public class C {
    public void M(bool b, string s) {
        var t = (b || true) ? s : null;
        t.ToString(); // unexpected warning CS8602: Possible dereference of a null reference.
    }
}

Formally, my proposal is that an expression is never null in an unreachable statement, never null when false after the constant true, never null when true after the constant false, and never null when false after expr is var x and similar patterns (which are always true but not a constant). These all have in common that the “current” state in the nullable analysis should be the unreachable state when evaluating the code in question. That means there is a nice bottleneck in the rvalue-visiting method where this can be implemented.

@gafter
Copy link
Member Author

gafter commented Mar 5, 2019

This was completed in #33648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Area-Language Design Need Design Review The end user experience design needs to be reviewed and approved. New Language Feature - Nullable Reference Types Nullable Reference Types
Projects
None yet
Development

No branches or pull requests

2 participants