dotnet / dotnet/csharpstandard

Null-conditional operator spec bug: E0 definition doesn't consider nullable value types

Open
#306 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

From https://github.com/dotnet/csharplang/blob/master/spec/expressions.md#null-conditional-operator

> For a null_conditional_expression E with a primary_expression P, let E0 be the expression obtained by textually removing the leading ? from each of the null_conditional_operations of E that have one.

Later, T0 is defined as the type of E0.

This seems to fall short in the case of nullable value types:

```
var d = (DateTime?)DateTime.Now;
var y = d?.Year; // valid
```
E0 according to the spec would be `d.Year`, which is not valid. What is T0 in this case?

https://github.com/dotnet/csharplang/blob/master/meetings/2014/LDM-2014-02-03.md#semantics clarified this detail explicitly:

> Where e0 is the same as e, except if e is of a nullable value type, in which case e0 is e.Value.

But that wording did not seem to make it into the spec.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.