csharpstandard icon indicating copy to clipboard operation
csharpstandard copied to clipboard

The token `notnull`. Is it a keyword? Is it explicitly not a keyword?

Open BillWagner opened this issue 11 months ago • 2 comments

In PR #830, this text was not included in the updates for nullable reference types:

The token notnull is neither a keyword nor a contextual keyword. When it is encountered, it will either:

  • Bind to a type named notnull
  • Bind to no type, in which case, it is interpreted as the nonnullable type constraint.

Should this text be added to the text for the notnull constraint?

#830 also includes a large example starting at line 503

Do we want to include that example as well.

Other changes in #830 have been reviewed by me and @RexJaeschke . They are either included, or have been excluded by design.

BillWagner avatar Jan 07 '25 22:01 BillWagner

I think by the definition of contextual keyword (§6.4.4) notnull is one, just like unmanaged is – so add it to §6.4.4

The similarity to unmanaged should carry over to how it is described. So in §15.2.5 we already have:

Because unmanaged is not a keyword, in primary_constraint the unmanaged constraint is always syntactically ambiguous with class_type. For compatibility reasons, if a name lookup (§12.8.4) of the name unmanaged succeeds it is treated as a class_type. Otherwise it is treated as the unmanaged constraint.

So for notnull we can use:

Because notnull is not a keyword, in primary_constraint the notnull constraint is always syntactically ambiguous with class_type. For compatibility reasons, if a name lookup (§12.8.4) of the name notnull succeeds it is treated as a class_type. Otherwise it is treated as the notnull constraint.

and insert it into §15.2.5.

Note that the description of nameof follows the same pattern as well.

Nigel-Ecma avatar Jan 21 '25 03:01 Nigel-Ecma

@Nigel-Ecma to create a PR along the lines he's outlined.

jskeet avatar Jan 22 '25 20:01 jskeet

Addressed by PR #1258

Nigel-Ecma avatar Oct 30 '25 21:10 Nigel-Ecma