dotnet / dotnet/csharpstandard

§12.4.1 Evaluation is *not* left-to-right

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

Description

Stemming from discussions on ECMA-TC49-TG2/spec#261 & ECMA-TC49-TG2/spec#993

§12.4.1 states:

> The order of evaluation of operators in an expression is determined by the **_precedence_** and **_associativity_** of
the operators (§12.4.2).
>
> Operands in an expression are evaluated from left to right.

But the last part is not correct. E.g. in §12.15 we read:

> A conditional expression of the form `b ? x : y` first evaluates the condition `b`. Then, if `b` is `true`, `x` is evaluated and becomes the result of the operation. Otherwise, `y` is evaluated and becomes the result of the operation. A conditional expression never evaluates both `x` and `y`.

So `b`, `x` & `y` are not evaluated strictly left-to-right...

This also impacts the short-circuit operators.

So it's "left-to-right but some may be skipped"?

This is important as the discussions show as if some are skipped then any side-effects are different.

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.