Commit 67a6b4f0 authored by Robert Griesemer's avatar Robert Griesemer

spec: fallthrough may not appear in last clause of a switch

Replacement for CL 7370053 which attempted to make fallthrough's
syntactically a part of switch statements. Because they may be
labeled, fixing that CL completely would require too much spec
surgery.

Fixes #4923.

R=r, iant, rsc, ken
CC=golang-dev
https://golang.org/cl/7416048
parent f235d5d8
<!--{ <!--{
"Title": "The Go Programming Language Specification", "Title": "The Go Programming Language Specification",
"Subtitle": "Version of February 11, 2013", "Subtitle": "Version of March 1, 2013",
"Path": "/ref/spec" "Path": "/ref/spec"
}--> }-->
...@@ -4154,12 +4154,14 @@ ExprSwitchCase = "case" ExpressionList | "default" . ...@@ -4154,12 +4154,14 @@ ExprSwitchCase = "case" ExpressionList | "default" .
</pre> </pre>
<p> <p>
In a case or default clause, In a case or default clause, the last non-empty statement
the last statement only may be a "fallthrough" statement may be a (possibly <a href="#Labeled_statements">labeled</a>)
<a href="#Fallthrough_statements">Fallthrough statement</a>) to <a href="#Fallthrough_statements">"fallthrough" statement</a> to
indicate that control should flow from the end of this clause to indicate that control should flow from the end of this clause to
the first statement of the next clause. the first statement of the next clause.
Otherwise control flows to the end of the "switch" statement. Otherwise control flows to the end of the "switch" statement.
A "fallthrough" statement may appear as the last statement of all
but the last clause of an expression switch.
</p> </p>
<p> <p>
...@@ -4798,9 +4800,8 @@ the "for" statement's block but the <code>goto</code> is not. ...@@ -4798,9 +4800,8 @@ the "for" statement's block but the <code>goto</code> is not.
<p> <p>
A "fallthrough" statement transfers control to the first statement of the A "fallthrough" statement transfers control to the first statement of the
next case clause in a expression "switch" statement (§<a href="#Expression_switches">Expression switches</a>). It may next case clause in a <a href="#Expression_switches">expression "switch" statement</a>.
be used only as the final non-empty statement in a case or default clause in an It may be used only as the final non-empty statement in such a clause.
expression "switch" statement.
</p> </p>
<pre class="ebnf"> <pre class="ebnf">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment