dotnet / dotnet/csharplang

Null propagation expression does not allow `!` as a nested operator form (VS 16.8, .NET 5)

Open
#3,393 8 comments 5 reactions 1 assignee Assigned to @jcouv View on GitHub
Implemented Needs ECMA Spec Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

See https://github.com/dotnet/docs/issues/17988

This means that the only correct parse of

```C#
var x = a?.b.c!.d.e;
```

is `(a?.b.c)!.d.e`, which prevents usage of null-forgiving in a chain of null-propagating accesses. To remedy this we could accept `!` as an optional token after every simple name in the null-propagating non-terminal.

cc @jcouv @gafter

----
Was discussed in LDM 6/17/2020. There is agreement/support, but we'll need to investigate and make a concrete syntax proposal. Also, there is desire to keep terminal `!` parsing as today: `a?.b.c!` would still parse as `(a?.b.c)!`.
For reference, the [current syntax](https://github.com/ljw1004/csharpspec/blob/gh-pages/csharp.g4).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.