Skip to content

[Nullable Reference Types] Specify nullable flow analysis lattice #1093

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

Closed
Tracked by #1085
BillWagner opened this issue Apr 26, 2024 · 5 comments
Closed
Tracked by #1085

[Nullable Reference Types] Specify nullable flow analysis lattice #1093

BillWagner opened this issue Apr 26, 2024 · 5 comments
Labels
meeting: discuss This issue should be discussed at the next TC49-TG2 meeting

Comments

@BillWagner
Copy link
Member

Specify the general rules for static flow analysis of nullable states. Namely, the standard should specify:

  • The possible null-state of a variable or expression (not-null or maybe-null)
  • The initial nullable state of a variable, based on the nullable context and its declared type
  • Some general rules about flow analysis and diagnostics.

That final bullet is fraught with risk. We don't want to constrain any future compiler innovations that improve static analysis. However, we need to paint some general view of the diagnostics to provide useful information both for compiler writers and C# programmers.

@BillWagner
Copy link
Member Author

See https://github.com/dotnet/csharpstandard/pull/1124/files#r1632781297 for more context here.

Depending on the resolution of that conversation, this PR should clarify how property accessors are handled. The result of invoking the set accessor, or the null-state of the value returned by a get accessor impacts the null-state of subsequent get accessors.

Stated non-normatively, the null state of a property is treated as though it is a variable.

That is not true for method invocations: Their result is not considered consistent between invocations.

@BillWagner
Copy link
Member Author

BillWagner commented Jul 10, 2024

From discussion during the 7/10 meeting:

We may to have three state:

  • not-null
  • maybe-null
  • oblivious

The existence of the oblivious state comes from any declaration when the annotation flag is disabled

@BillWagner BillWagner added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Sep 18, 2024
@BillWagner
Copy link
Member Author

We should discuss this issue and #1092 in our next meeting.

Does any of the information on the static analysis belong in the standard?

If so, what?

@BillWagner
Copy link
Member Author

While working on the PR for generic type constraints, I looked again at #700.

That contains normative language on requirements to initialize static and instance fields either in initializers or all constructors. Should we add either conditionally normative or informative language regarding those rules?

@jskeet
Copy link
Contributor

jskeet commented Oct 2, 2024

Decision 2024-10-02: closing as not needed

@jskeet jskeet closed this as completed Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meeting: discuss This issue should be discussed at the next TC49-TG2 meeting
Projects
None yet
Development

No branches or pull requests

2 participants