Skip to content

When we compute a nullable annotation in flow analysis, should we use the context? #33639

@gafter

Description

@gafter

The current LDM position is that we use the annotation context to compute the annotations (oblivious versus non-nullable). We don't currently do this.

For example, in the declaration of a local variable. If a local variable is declared

string s;

is it oblivious in a disabled state, but non-null in an enabled state? For locals, I believe oblivious acts the same as nullable (i.e. the state you get on reading is based on tracking, but you're allowed to assign null).

What if the local's type is inferred?

#nullable disable
var s = ""; // Is s oblivious?

Also, when doing type inference, would we infer oblivious in a context where the nullability annotations are disabled, but non-null where nullability annotations are enabled?

#nonnull enable
T Copy<T>(T t) => t;
T M<T>(T t)
{
    // warning: possibly null dereference; the inferred type argument to Copy is unannotated
    Copy(t).ToString();

#nonnull disable
    // no warning; the inferred type argument to Copy is oblivious
    Copy(t).ToString();
}

If t above were declared as a nullable reference type (possibly containing null), would we get an annotated inferred type in both contexts?

Metadata

Metadata

Assignees

No one assigned

    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