From 2dde4f5d2906eab25625f6a260a2eb80be9ce572 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
Date: Thu, 24 May 2012 10:59:48 -0700
Subject: [PATCH] spec: clarify evaluation order of "i, x[i] = range ..."
Part of fix for issue 3464.
R=golang-dev, rsc, mirtchovski, iant, r
CC=golang-dev
https://golang.org/cl/6246045
---
doc/go_spec.html | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/doc/go_spec.html b/doc/go_spec.html
index 8cb257a59fb..78197351f28 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
@@ -3866,7 +3866,11 @@ x, _ = f() // ignore second value returned by f()
In the second form, the number of operands on the left must equal the number
of expressions on the right, each of which must be single-valued, and the
nth expression on the right is assigned to the nth
-operand on the left. The assignment proceeds in two phases.
+operand on the left.
+
+
+
+The assignment proceeds in two phases.
First, the operands of index expressions
and pointer indirections
(including implicit pointer indirections in selectors)
@@ -3885,13 +3889,20 @@ i, x[i] = 1, 2 // set i = 1, x[0] = 2
i = 0
x[i], i = 2, 1 // set x[0] = 2, i = 1
-x[0], x[0] = 1, 2 // set x[0] = 1, then x[0] = 2 (so x[0] = 2 at end)
+x[0], x[0] = 1, 2 // set x[0] = 1, then x[0] = 2 (so x[0] == 2 at end)
x[1], x[3] = 4, 5 // set x[1] = 4, then panic setting x[3] = 5.
type Point struct { x, y int }
var p *Point
x[2], p.x = 6, 7 // set x[2] = 6, then panic setting p.x = 7
+
+i = 2
+x = []int{3, 5, 7}
+for i, x[i] = range x { // set i, x[2] = 0, x[0]
+ break
+}
+// after this loop, i == 0 and x == []int{3, 5, 3}