mirror of
https://github.com/golang/go
synced 2024-11-20 00:44:45 -07:00
go/types: trailing semis are ok after valid fallthrough
Fixes #15376. Change-Id: I9ece80f26b83be129671c961120c157da2ac0079 Reviewed-on: https://go-review.googlesource.com/22270 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
a4dd6ea152
commit
082f464823
@ -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) {
|
||||
|
17
src/go/types/testdata/stmt0.src
vendored
17
src/go/types/testdata/stmt0.src
vendored
@ -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:
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user