Skip to content
This repository has been archived by the owner on Sep 17, 2018. It is now read-only.

Commit

Permalink
go spec: inside functions, variables must be evaluated.
Browse files Browse the repository at this point in the history
Fixes issue 1612.

R=r, rsc, iant, ken, remyoudompheng, ken, r
CC=golang-dev
http://codereview.appspot.com/5700068
  • Loading branch information
griesemer committed Feb 29, 2012
1 parent dbcbb62 commit 9177d35
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of February 23, 2012"
"Subtitle": "Version of February 28, 2012"
}-->

<!--
Expand Down Expand Up @@ -1832,6 +1832,13 @@ <h3 id="Variable_declarations">Variable declarations</h3>
If the type is absent and the corresponding expression evaluates to an
untyped <a href="#Constants">constant</a>, the type of the declared variable
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>

Expand All @@ -1844,8 +1851,8 @@ <h3 id="Short_variable_declarations">Short variable declarations</h3>
</pre>

<p>
It is a shorthand for a regular variable declaration with
initializer expressions but no types:
It is a shorthand for a regular <a href="#Variable_declarations">variable declaration</a>
with initializer expressions but no types:
</p>

<pre class="grammar">
Expand Down Expand Up @@ -4238,7 +4245,9 @@ <h3 id="For_statements">For statements</h3>
</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
and their <a href="#Declarations_and_scope">scope</a> ends at the end of the "for"
statement; they are re-used in each iteration.
Expand Down

0 comments on commit 9177d35

Please sign in to comment.