From f1cc0f44e384ff33179a2cc6d19369237cdc64cd Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 9 Jan 2013 11:31:32 -0800 Subject: [PATCH] spec: clarify short variable declaration corner cases Fixes #4612. R=rsc, iant, ken, r CC=golang-dev https://golang.org/cl/7076043 --- doc/go_spec.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 59abbece68..7a2a00670b 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1920,7 +1920,7 @@ _, y, _ := coord(p) // coord() returns three values; only interested in y coord

Unlike regular variable declarations, a short variable declaration may redeclare variables provided they -were originally declared in the same block with the same type, and at +were originally declared earlier in the same block with the same type, and at least one of the non-blank variables is new. As a consequence, redeclaration can only appear in a multi-variable short declaration. Redeclaration does not introduce a new @@ -1930,6 +1930,7 @@ variable; it just assigns a new value to the original.

 field1, offset := nextField(str, 0)
 field2, offset := nextField(str, offset)  // redeclares offset
+a, a := 1, 2                              // illegal: double declaration of a or no new variable if a was declared elsewhere
 

-- 2.48.1