Fixes #15376.
Change-Id: I9ece80f26b83be129671c961120c157da2ac0079
Reviewed-on: https://go-review.googlesource.com/22270
Reviewed-by: Alan Donovan <adonovan@google.com>
}
}
+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) {
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:
}
switch x {
case 0:
goto L1
- L1: fallthrough
+ L1: fallthrough; ;
case 1:
goto L2
goto L3
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:
}
}