cmd/gc: reject incorrect use of fallthrough.

Fixes #6500.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/14920053
This commit is contained in:
Rémy Oudompheng 2014-02-19 07:55:03 +01:00
parent 8b0b994c08
commit 96678f9dc0
4 changed files with 286 additions and 253 deletions

View file

@ -557,6 +557,7 @@ caseblock:
// This is so that the stmt_list action doesn't look at
// the case tokens if the stmt_list is empty.
yylast = yychar;
$1->xoffset = block;
}
stmt_list
{
@ -1730,6 +1731,7 @@ non_dcl_stmt:
{
// will be converted to OFALL
$$ = nod(OXFALL, N, N);
$$->xoffset = block;
}
| LBREAK onew_name
{

View file

@ -317,7 +317,7 @@ casebody(Node *sw, Node *typeswvar)
// botch - shouldn't fall thru declaration
last = stat->end->n;
if(last->op == OXFALL) {
if(last->xoffset == n->xoffset && last->op == OXFALL) {
if(typeswvar) {
setlineno(last);
yyerror("cannot fallthrough in type switch");

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,29 @@
// errorcheck
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 6500: missing error when fallthrough appears in a block.
package main
func main() {
var x int
switch x {
case 0:
{
fallthrough // ERROR "fallthrough"
}
case 1:
{
switch x {
case 2:
fallthrough
case 3:
}
}
fallthrough
default:
}
}