Skip to content

Null conditional operators for coalescing, assignment and member access #223

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

Merged
merged 7 commits into from
Feb 19, 2020
13 changes: 13 additions & 0 deletions 1-Draft/RFCNNN-Null-conditional-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ The `??` operator checks the left hand side to be null or undefined and returns

If the module `Pester` is not installed, then install the module.

### Updates to operator precedence

The operator precedence token flags will be updated to add gaps and place the null coalesce opeator at position 7, above comparison and below add/subtract.
Currently, the binary operator mask is set at `0x07`, which will be updated to `0x0f`.
This will ensure that `??` is evaluated before operators like `-eq`, `-and`, `-bor` etc, but after `+` and `-`.

This enables scenarios like:
```PowerShell
'x' -eq $null ?? 'x' evaluates to 'x' -eq ($null ?? 'x')

2 + $null ?? 3 evaluates to 2 + ($null ?? 3)
```

### Additional considerations

The `??=` and `??` operators are binary operators and check for the value of the left hand side to be null or an undefined variable.
Expand Down