]> Cypherpunks repositories - gostls13.git/commitdiff
spec: clarify evaluation order
authorRobert Griesemer <gri@golang.org>
Thu, 9 Aug 2012 18:50:16 +0000 (11:50 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 9 Aug 2012 18:50:16 +0000 (11:50 -0700)
Fixes #3852.

R=r, rsc, iant, ken
CC=golang-dev
https://golang.org/cl/6441102

doc/go_spec.html

index 94ab9bbe7fe29de8da6482f99db1046ddf2d6aa8..84c7d510e9b53d5ae9e3e70ad4cdbb7d9c33bf4e 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "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