-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Null state in unreachable code #32047
Copy link
Copy link
Closed
Labels
Area-CompilersArea-Language DesignFeature - Nullable Reference TypesNullable Reference TypesNullable Reference TypesNeed Design ReviewThe end user experience design needs to be reviewed and approved.The end user experience design needs to be reviewed and approved.
Milestone
Metadata
Metadata
Assignees
Labels
Area-CompilersArea-Language DesignFeature - Nullable Reference TypesNullable Reference TypesNullable Reference TypesNeed Design ReviewThe end user experience design needs to be reviewed and approved.The end user experience design needs to be reviewed and approved.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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 expressionnullis 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:
Formally, my proposal is that an expression is never
nullin an unreachable statement, nevernullwhen false after the constant true, nevernullwhen true after the constant false, and nevernullwhen false afterexpr is var xand 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.