[MemberNotNull(When)] annotations don't work on local functions inside member initializers inside non-static closure chains #76528
Labels
Area-Compilers
Feature - Nullable Reference Types
Nullable Reference Types
untriaged
Issues and PRs which have not yet been triaged by a lead
Version Used:
Steps to Reproduce:
Compile the following code (sharplab.io)
Expected Behavior:
No warning fo
field.Length
access inProp1
. The local function ensures that the member is not nullable and declares it in its annotationActual Behavior:
Incorrect CS8602 warning for
Prop1
Notes:
You can get rid of the false warning by adding
static
to any of the closures in this example (either to the lambda itself or to the local function) e.g.However, it seems that this shouldn't be required -
static
only disallows closures and shouldn't affect the behavior when there are none.[MemberNotNull(When)]
doesn't require any static modifiers in other members, e.g.:The text was updated successfully, but these errors were encountered: