Commit 96678f9d authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/gc: reject incorrect use of fallthrough.

Fixes #6500.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/14920053
parent 8b0b994c
......@@ -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");
......
This diff is collapsed.
// 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:
}
}
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