1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:44:39 -07:00

spec: disallow goto into blocks

R=gri, r, r
CC=golang-dev
https://golang.org/cl/4631045
This commit is contained in:
Russ Cox 2011-06-17 12:49:04 -04:00
parent 21e75da486
commit f4c7db0ed9

View File

@ -1,5 +1,5 @@
<!-- title The Go Programming Language Specification --> <!-- title The Go Programming Language Specification -->
<!-- subtitle Version of June 13, 2011 --> <!-- subtitle Version of June 17, 2011 -->
<!-- <!--
TODO TODO
@ -4393,8 +4393,8 @@ goto Error
<p> <p>
Executing the "goto" statement must not cause any variables to come into Executing the "goto" statement must not cause any variables to come into
scope that were not already in scope at the point of the goto. For <a href="#Declarations_and_scope">scope</a> that were not already in scope at the point of the goto.
instance, this example: For instance, this example:
</p> </p>
<pre> <pre>
@ -4406,9 +4406,29 @@ L:
<p> <p>
is erroneous because the jump to label <code>L</code> skips is erroneous because the jump to label <code>L</code> skips
the creation of <code>v</code>. the creation of <code>v</code>.
<!-- </p>
(<span class="alert">TODO: Eliminate in favor of used and not set errors?</span>)
--> <p>
A "goto" statement outside a <a href="#Blocks">block</a> cannot jump to a label inside that block.
For instance, this example:
</p>
<pre>
if n%2 == 1 {
goto L1
}
for n &gt; 0 {
f()
n--
L1:
f()
n--
}
</pre>
<p>
is erroneous because the label <code>L1</code> is inside
the "for" statement's block but the <code>goto</code> is not.
</p> </p>
<h3 id="Fallthrough_statements">Fallthrough statements</h3> <h3 id="Fallthrough_statements">Fallthrough statements</h3>
@ -5244,7 +5264,6 @@ The following minimal alignment properties are guaranteed:
<span class="alert"> <span class="alert">
<h2 id="Implementation_differences">Implementation differences - TODO</h2> <h2 id="Implementation_differences">Implementation differences - TODO</h2>
<ul> <ul>
<li>The restriction on <code>goto</code> statements and targets (no intervening declarations) is not honored.</li>
<li><code>len(a)</code> is only a constant if <code>a</code> is a (qualified) identifier denoting an array or pointer to an array.</li> <li><code>len(a)</code> is only a constant if <code>a</code> is a (qualified) identifier denoting an array or pointer to an array.</li>
<li><code>nil</code> maps are not treated like empty maps.</li> <li><code>nil</code> maps are not treated like empty maps.</li>
<li>Trying to send/receive from a <code>nil</code> channel causes a run-time panic.</li> <li>Trying to send/receive from a <code>nil</code> channel causes a run-time panic.</li>