From 2bea43b0e7f3e636ffc8239f9d3fccdd5d763c8b Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 11 May 2022 16:21:45 -0700 Subject: [PATCH] spec: state that variable names must be unique in short var decls Fixes #45652. Change-Id: I5e1434480c12815369a6ce204f3729eb63139125 Reviewed-on: https://go-review.googlesource.com/c/go/+/405757 Reviewed-by: Ian Lance Taylor Reviewed-by: Matthew Dempsky --- doc/go_spec.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 069d33ba55..4f647cac10 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -2761,7 +2761,7 @@ It is shorthand for a regular variable declarat with initializer expressions but no types:

-
+
 "var" IdentifierList = ExpressionList .
 
@@ -2780,12 +2780,14 @@ variables provided they were originally declared earlier in the same block 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 variable; it just assigns a new value to the original. +The non-blank variable names on the left side of := +must be unique.

 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
+x, y, x := 1, 2, 3                        // illegal: x repeated on left side of :=
 

-- 2.50.0