mirror of
https://github.com/golang/go
synced 2024-11-22 00:24:41 -07:00
spec: clarify evaluation order
Fixes #3852. R=r, rsc, iant, ken CC=golang-dev https://golang.org/cl/6441102
This commit is contained in:
parent
20bf1a94e1
commit
f05a91e18b
@ -1,6 +1,6 @@
|
|||||||
<!--{
|
<!--{
|
||||||
"Title": "The Go Programming Language Specification",
|
"Title": "The Go Programming Language Specification",
|
||||||
"Subtitle": "Version of July 11, 2012",
|
"Subtitle": "Version of August 9, 2012",
|
||||||
"Path": "/ref/spec"
|
"Path": "/ref/spec"
|
||||||
}-->
|
}-->
|
||||||
|
|
||||||
@ -3694,8 +3694,10 @@ overflow etc. errors being caught.
|
|||||||
<h3 id="Order_of_evaluation">Order of evaluation</h3>
|
<h3 id="Order_of_evaluation">Order of evaluation</h3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
When evaluating the elements of an assignment or expression,
|
When evaluating the <a href="#Operands">operands</a> of an expression,
|
||||||
all function calls, method calls and
|
<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
|
communication operations are evaluated in lexical left-to-right
|
||||||
order.
|
order.
|
||||||
</p>
|
</p>
|
||||||
@ -3715,6 +3717,12 @@ and indexing of <code>x</code> and the evaluation
|
|||||||
of <code>y</code> is not specified.
|
of <code>y</code> is not specified.
|
||||||
</p>
|
</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>
|
<p>
|
||||||
Floating-point operations within a single expression are evaluated according to
|
Floating-point operations within a single expression are evaluated according to
|
||||||
the associativity of the operators. Explicit parentheses affect the evaluation
|
the associativity of the operators. Explicit parentheses affect the evaluation
|
||||||
|
Loading…
Reference in New Issue
Block a user