mirror of
https://github.com/golang/go
synced 2024-11-21 22:44:40 -07:00
go spec: inside functions, variables must be evaluated.
Fixes #1612. R=r, rsc, iant, ken, remyoudompheng, ken, r CC=golang-dev https://golang.org/cl/5700068
This commit is contained in:
parent
b69fa69a8b
commit
2c9e1637d2
@ -1,6 +1,6 @@
|
|||||||
<!--{
|
<!--{
|
||||||
"Title": "The Go Programming Language Specification",
|
"Title": "The Go Programming Language Specification",
|
||||||
"Subtitle": "Version of February 23, 2012"
|
"Subtitle": "Version of February 28, 2012"
|
||||||
}-->
|
}-->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@ -1832,6 +1832,13 @@ of the expression list.
|
|||||||
If the type is absent and the corresponding expression evaluates to an
|
If the type is absent and the corresponding expression evaluates to an
|
||||||
untyped <a href="#Constants">constant</a>, the type of the declared variable
|
untyped <a href="#Constants">constant</a>, the type of the declared variable
|
||||||
is as described in §<a href="#Assignments">Assignments</a>.
|
is as described in §<a href="#Assignments">Assignments</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Implementation restriction: A compiler may make it illegal to declare a variable
|
||||||
|
inside a <a href="#Function_declarations">function body</a> if the variable is
|
||||||
|
never used.
|
||||||
|
</p>
|
||||||
|
|
||||||
<h3 id="Short_variable_declarations">Short variable declarations</h3>
|
<h3 id="Short_variable_declarations">Short variable declarations</h3>
|
||||||
|
|
||||||
@ -1844,8 +1851,8 @@ ShortVarDecl = IdentifierList ":=" ExpressionList .
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
It is a shorthand for a regular variable declaration with
|
It is a shorthand for a regular <a href="#Variable_declarations">variable declaration</a>
|
||||||
initializer expressions but no types:
|
with initializer expressions but no types:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre class="grammar">
|
<pre class="grammar">
|
||||||
@ -4238,7 +4245,9 @@ iteration variables as in an <a href="#Assignments">assignment statement</a>.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The iteration variables may be declared by the "range" clause (<code>:=</code>).
|
The iteration variables may be declared by the "range" using a form of
|
||||||
|
<a href="#Short_variable_declarations">short variable declaration</a>
|
||||||
|
(<code>:=</code>).
|
||||||
In this case their types are set to the types of the respective iteration values
|
In this case their types are set to the types of the respective iteration values
|
||||||
and their <a href="#Declarations_and_scope">scope</a> ends at the end of the "for"
|
and their <a href="#Declarations_and_scope">scope</a> ends at the end of the "for"
|
||||||
statement; they are re-used in each iteration.
|
statement; they are re-used in each iteration.
|
||||||
|
Loading…
Reference in New Issue
Block a user