Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: An alternative approach to handling "null conditional" ops #251

Merged
merged 23 commits into from
Oct 20, 2021
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f4351c6
First pass at an alternative approach to handling "null conditional" …
Nigel-Ecma Apr 5, 2021
f881f34
Update expressions.md
Nigel-Ecma Apr 28, 2021
91fe31b
Update lexical-structure.md
Nigel-Ecma Apr 28, 2021
a98d5d7
Update statements.md
Nigel-Ecma Apr 28, 2021
4ee7b60
Extend grammar of null_conditional_member_access and null_conditional…
Nigel-Ecma May 3, 2021
64659e0
Missed one alternative of unconditional_access_part
Nigel-Ecma May 3, 2021
247e2be
Merge branch 'dotnet:draft-v6' into alt-null-conditional-ops
Nigel-Ecma May 31, 2021
d264cee
Updated to now include:
Nigel-Ecma May 31, 2021
c238d13
fix adjacent key typo
Nigel-Ecma May 31, 2021
d147b8b
Missed out lexical-structure.md
Nigel-Ecma May 31, 2021
08607f9
Update standard/expressions.md
Nigel-Ecma Jun 25, 2021
854f9d6
Update standard/expressions.md
Nigel-Ecma Jun 25, 2021
5ed92c2
- A number of small changes resolving issues raised in the comments.
Nigel-Ecma Jun 25, 2021
e4affe1
Fix some bad links
Nigel-Ecma Jun 25, 2021
181462d
And yet more link fixes...
Nigel-Ecma Jun 25, 2021
4d995f7
And I continue to whittle 'em down...
Nigel-Ecma Jun 25, 2021
1918dae
Addressed some issues raised and made a few corrections/improvements …
Nigel-Ecma Sep 14, 2021
78f7fba
Merge in changes to draft-v6 since all-null-conditional-ops branched off
Nigel-Ecma Sep 21, 2021
10c969b
Rename captured_access to dependent_access
Nigel-Ecma Sep 26, 2021
59226a8
Merge branch 'draft-v6' into alt-null-conditional-ops to bring in lat…
Nigel-Ecma Sep 27, 2021
04a3841
Merge in changes from draft-v6 and keep grammar.md up-to-date
Nigel-Ecma Sep 27, 2021
e1133a3
Apply suggestions from code review
Nigel-Ecma Oct 17, 2021
4457d3e
Fix editing snafu unearthed by Bill & Jon. Mea culpa.
Nigel-Ecma Oct 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions standard/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1279,11 +1279,16 @@ In a member access of the form `E.I`, if `E` is a single identifier, and if the

### §null-conditional-member-access Null Conditional Member Access
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just been trying to figure out how this works in a couple of cases, and while I think it's the right approach, we may need a bit more explanation.

For example consider:

string x = null;
int? y = x?.GetHashCode();

My understanding is that that is a null_conditional_member_access with a dependent_access of () - so we get the null value. It's not a null_conditional_invocation_expression, because that's only used in places where the result (if any) is discarded. Is that the case? If so, it's a bit confusing because x.GetHashCode() is an invocation expresson, isn't it?

I'm not suggesting that we change any of the existing text - just consider adding an example/note.


A *null_conditional_member_access* consists of a *primary_expression* followed by a "`?.`" token, followed by an *Identifier*, optionally followed by a *type_argument_list*.
A *null_conditional_member_access* consists of a *primary_expression* followed by a "`?.`" token, followed by an *Identifier* with an optional *type_argument_list*, followed by zero or more *unconditional_access_part*s.
Nigel-Ecma marked this conversation as resolved.
Show resolved Hide resolved

```ANTLR
null_conditional_member_access
: primary_expression '?.' Identifier type_argument_list?
: primary_expression '?.' Identifier type_argument_list? unconditional_access_part*
Nigel-Ecma marked this conversation as resolved.
Show resolved Hide resolved
;

unconditional_access_part
: '.' Identifier type_argument_list?
| '[' argument_list ']'
;
```

Expand Down Expand Up @@ -1547,11 +1552,11 @@ Depending on the context in which it is used, an indexer access causes invocatio

### §null-conditional-element-access Null Conditional Element Access

A *null_conditional_element_access* consists of a *primary_no_array_creation_expression* followed by a "`?[`" token, followed by an *argument_list*, followed by a "`]`" token.
A *null_conditional_element_access* consists of a *primary_no_array_creation_expression* followed by a "`?[`" token, followed by an *argument_list*, followed by a "`]`" token, followed by zero or more *unconditional_access_part*s.
Nigel-Ecma marked this conversation as resolved.
Show resolved Hide resolved

```ANTLR
null_conditional_element_access
: primary_no_array_creation_expression '?[' argument_list ']'
: primary_no_array_creation_expression '?[' argument_list ']' unconditional_access_part*
;
```

Expand Down