Commit f05a91e1 authored by Robert Griesemer's avatar Robert Griesemer

spec: clarify evaluation order

Fixes #3852.

R=r, rsc, iant, ken
CC=golang-dev
https://golang.org/cl/6441102
parent 20bf1a94
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of July 11, 2012",
"Subtitle": "Version of August 9, 2012",
"Path": "/ref/spec"
}-->
......@@ -3694,8 +3694,10 @@ overflow etc. errors being caught.
<h3 id="Order_of_evaluation">Order of evaluation</h3>
<p>
When evaluating the elements of an assignment or expression,
all function calls, method calls and
When evaluating the <a href="#Operands">operands</a> of an expression,
<a href="#Assignments">assignment</a>, or
<a href="#Return_statements">return statement</a>,
all function calls, method calls, and
communication operations are evaluated in lexical left-to-right
order.
</p>
......@@ -3715,6 +3717,12 @@ and indexing of <code>x</code> and the evaluation
of <code>y</code> is not specified.
</p>
<pre>
a := 1
f := func() int { a = 2; return 3 }
x := []int{a, f()} // x may be [1, 3] or [2, 3]: evaluation order between a and f() is not specified
</pre>
<p>
Floating-point operations within a single expression are evaluated according to
the associativity of the operators. Explicit parentheses affect the evaluation
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment