Proposal: Improve analysis of [MaybeNull]T values #2946
Labels
Implemented Needs ECMA Spec
This feature has been implemented in C#, but still needs to be merged into the ECMA specification
Proposal champion
Proposal
Milestone
Improve analysis of
[MaybeNull]T
values by adding a third possible flow state.Additional flow state
A third flow state is added that represents maybe null even when substituted with a non-nullable reference type. The additional state applies only to values of type parameters that are not constrained not nullable. Flow analysis will use two bits for each tracked value.
The merging rules are unchanged:
Join()
uses bitwise|
andMeet()
uses bitwise&
.Member signatures affect method analysis
Attributes on members, including attributes on the containing method signature, are considered when analyzing the method body.
No W warnings
Locals cannot use
[MaybeNull]
and neither can explicit casts. Because of that limitation, W warnings are not reported for unconstrained types.Warnings are produced for compound types though:
No warning for null expressions
Expressions (of a type parameter type not constrained to not nullable) that may produce null values are treated as
MaybeDefault
. Warnings are not reported for the expressions directly.Type inference
[MaybeNull]
is ignored in method type inference.Best type algorithm relies on the merging of states to choose [MaybeNull]T over T.
LDM Notes
[MaybeNull] T
)The text was updated successfully, but these errors were encountered: