dotnet / dotnet/csharpstandard

12.15 Conditional operator

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

Description

In 12.15 Conditional operator we have the rules for finding the common type of the second and third operands:

> The second and third operands, `x` and `y`, of the `?:` operator control the type of the conditional expression.
> - If `x` has type `X` and `y` has type `Y` then,
> - If `X` and `Y` are the same type, then this is the type of the conditional expression.
> - Otherwise, if an implicit conversion (§11.2) exists from `X` to `Y`, but not from `Y` to `X`, then `Y` is the type of the conditional expression.
> - Otherwise, if an implicit enumeration conversion (§11.2.4) exists from `X` to `Y`, then `Y` is the type of the conditional expression.
> - Otherwise, if an implicit enumeration conversion (§11.2.4) exists from `Y` to `X`, then `X` is the type of the conditional expression.
> - Otherwise, if an implicit conversion (§11.2) exists from `Y` to `X`, but not from `X` to `Y`, then `X` is the type of the conditional expression.
> - Otherwise, no expression type can be determined, and a compile-time error occurs.
> - If only one of `x` and `y` has a type, and both `x` and `y` are implicitly convertible to that type, then that is the type of the conditional expression.
> - Otherwise, no expression type can be determined, and a compile-time error occurs.

However the phrase "if an implicit enumeration conversion (§11.2.4) exists from `X` to `Y`" makes no sense, as an implicit enumeration conversion is a *conversion from expression*, whereas `X` is a type, not an expression. This error appears twice. I think the "from" variable should be the lower-case version, which indicates the corresponding expression.

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.