From ab4821d468aa6b8d22e5ef935aa4945d4203a5f1 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sat, 22 Sep 2012 05:54:35 +1000 Subject: [PATCH] [release-branch.go1] spec: clarify evaluation order MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ««« backport 6beada1bf6c2 spec: clarify evaluation order Fixes #3852. R=r, rsc, iant, ken CC=golang-dev https://golang.org/cl/6441102 »»» --- doc/go_spec.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 94ab9bbe7f..84c7d510e9 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -3694,8 +3694,10 @@ overflow etc. errors being caught.

Order of evaluation

-When evaluating the elements of an assignment or expression, -all function calls, method calls and +When evaluating the operands of an expression, +assignment, or +return statement, +all function calls, method calls, and communication operations are evaluated in lexical left-to-right order.

@@ -3715,6 +3717,12 @@ and indexing of x and the evaluation of y is not specified.

+
+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
+
+

Floating-point operations within a single expression are evaluated according to the associativity of the operators. Explicit parentheses affect the evaluation -- 2.50.0