mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
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:
parent
8b0b994c08
commit
96678f9dc0
4 changed files with 286 additions and 253 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
29
test/fixedbugs/issue6500.go
Normal file
29
test/fixedbugs/issue6500.go
Normal 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:
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue