- Proposed
- Prototype: None
- Implementation: None
- Specification: See below
There is a situation in which the current common-type algorithm results are counter-intuitive, and results in the programmer adding what feels like a redundant cast to the code. With this change, an expression such as condition ? 1 : null
would result in a value of type int?
.
This is a common cause of what feels to the programmer like needless boilerplate code.
We modify the specification for finding the best common type of a set of expressions to affect the following situation:
- If one expression is of a non-nullable value type
T
and the other is a null literal, the result is of typeT?
.
This is expected to affect the following aspects of the language:
- the ternary expression
- implicitly types array creation expression
- inferring the return type of a lambda for type inference
There may be some incompatibilities introduced by this proposal.
None.
- What is the severity of incompatibility introduced by this proposal, and how can it be moderated?
None.