]> Cypherpunks.ru repositories - gostls13.git/commitdiff
spec: state that variable names must be unique in short var decls
authorRobert Griesemer <gri@golang.org>
Wed, 11 May 2022 23:21:45 +0000 (16:21 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 12 May 2022 04:47:29 +0000 (04:47 +0000)
Fixes #45652.

Change-Id: I5e1434480c12815369a6ce204f3729eb63139125
Reviewed-on: https://go-review.googlesource.com/c/go/+/405757
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
doc/go_spec.html

index 069d33ba55de57b002c55ce6e395a08475210111..4f647cac10da7846b52871c99b70876ce4253f38 100644 (file)
@@ -2761,7 +2761,7 @@ It is shorthand for a regular <a href="#Variable_declarations">variable declarat
 with initializer expressions but no types:
 </p>
 
-<pre class="grammar">
+<pre class="ebnf">
 "var" IdentifierList = ExpressionList .
 </pre>
 
@@ -2780,12 +2780,14 @@ variables provided they were originally declared earlier in the same block
 and at least one of the non-<a href="#Blank_identifier">blank</a> 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 <code>:=</code>
+must be <a href="#Uniqueness_of_identifiers">unique</a>.
 </p>
 
 <pre>
 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 :=
 </pre>
 
 <p>