From f05a91e18b4a3e1e962e1013cbf6ab16e120d190 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 9 Aug 2012 11:50:16 -0700 Subject: [PATCH] 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