mirror of
https://github.com/golang/go
synced 2024-11-25 11:57:58 -07:00
spec change for redeclaration
R=iant,gri DELTA=14 (14 added, 0 deleted, 0 changed) OCL=27615 CL=27618
This commit is contained in:
parent
549a60046b
commit
2a1683a007
@ -1674,6 +1674,20 @@ variables will be assigned the corresponding values.
|
|||||||
r, w := os.Pipe(fd); // os.Pipe() returns two values
|
r, w := os.Pipe(fd); // os.Pipe() returns two values
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
A short variable declaration may redeclare variables provided they
|
||||||
|
were originally declared in the same block with the same type, and at
|
||||||
|
least one of the 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.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
field1, offset := nextField(str, 0);
|
||||||
|
field2, offset := nextField(str, offset); // redeclares offset
|
||||||
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Short variable declarations may appear only inside functions.
|
Short variable declarations may appear only inside functions.
|
||||||
In some contexts such as the initializers for <code>if</code>,
|
In some contexts such as the initializers for <code>if</code>,
|
||||||
|
Loading…
Reference in New Issue
Block a user