Commit 082f4648 authored by Robert Griesemer's avatar Robert Griesemer

go/types: trailing semis are ok after valid fallthrough

Fixes #15376.

Change-Id: I9ece80f26b83be129671c961120c157da2ac0079
Reviewed-on: https://go-review.googlesource.com/22270Reviewed-by: 's avatarAlan Donovan <adonovan@google.com>
parent a4dd6ea1
......@@ -83,9 +83,19 @@ func (check *Checker) simpleStmt(s ast.Stmt) {
}
}
func trimTrailingEmptyStmts(list []ast.Stmt) []ast.Stmt {
for i := len(list); i > 0; i-- {
if _, ok := list[i-1].(*ast.EmptyStmt); !ok {
return list[:i]
}
}
return nil
}
func (check *Checker) stmtList(ctxt stmtContext, list []ast.Stmt) {
ok := ctxt&fallthroughOk != 0
inner := ctxt &^ fallthroughOk
list = trimTrailingEmptyStmts(list) // trailing empty statements are "invisible" to fallthrough analysis
for i, s := range list {
inner := inner
if ok && i+1 == len(list) {
......
......@@ -531,16 +531,18 @@ func switches1() {
case 1:
fallthrough
case 2:
default:
fallthrough
fallthrough; ; ; // trailing empty statements are ok
case 3:
default:
fallthrough; ;
case 4:
fallthrough /* ERROR "fallthrough statement out of place" */
}
var y interface{}
switch y.(type) {
case int:
fallthrough /* ERROR "fallthrough statement out of place" */
fallthrough /* ERROR "fallthrough statement out of place" */ ; ; ;
default:
}
......@@ -554,7 +556,7 @@ func switches1() {
switch x {
case 0:
goto L1
L1: fallthrough
L1: fallthrough; ;
case 1:
goto L2
goto L3
......@@ -576,9 +578,16 @@ func switches1() {
switch x {
case 0:
fallthrough; ;
case 1:
{
fallthrough /* ERROR "fallthrough statement out of place" */
}
case 2:
fallthrough
case 3:
fallthrough /* ERROR "fallthrough statement out of place" */
{ /* empty block is not an empty statement */ }; ;
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