Skip to content

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

@latkin

Description

@latkin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions