return varDeclPos.IsKnown() && slices.Contains(badJumps, jmp)
}
- var stmtBranches func(syntax.Stmt)
- stmtBranches = func(s syntax.Stmt) {
+ var stmtBranches func(*syntax.LabeledStmt, syntax.Stmt)
+ stmtBranches = func(lstmt *syntax.LabeledStmt, s syntax.Stmt) {
switch s := s.(type) {
case *syntax.DeclStmt:
for _, d := range s.DeclList {
fwdJumps = fwdJumps[:i]
lstmt = s
}
- stmtBranches(s.Stmt)
+ stmtBranches(lstmt, s.Stmt)
case *syntax.BranchStmt:
if s.Label == nil {
fwdJumps = append(fwdJumps, check.blockBranches(all, b, lstmt, s.List)...)
case *syntax.IfStmt:
- stmtBranches(s.Then)
+ stmtBranches(lstmt, s.Then)
if s.Else != nil {
- stmtBranches(s.Else)
+ stmtBranches(lstmt, s.Else)
}
case *syntax.SwitchStmt:
}
case *syntax.ForStmt:
- stmtBranches(s.Body)
+ stmtBranches(lstmt, s.Body)
}
}
for _, s := range list {
- stmtBranches(s)
+ stmtBranches(nil, s)
}
return fwdJumps
fwdJumps = append(fwdJumps, check.blockBranches(all, b, lstmt, list)...)
}
- var stmtBranches func(ast.Stmt)
- stmtBranches = func(s ast.Stmt) {
+ var stmtBranches func(*ast.LabeledStmt, ast.Stmt)
+ stmtBranches = func(lstmt *ast.LabeledStmt, s ast.Stmt) {
switch s := s.(type) {
case *ast.DeclStmt:
if d, _ := s.Decl.(*ast.GenDecl); d != nil && d.Tok == token.VAR {
fwdJumps = fwdJumps[:i]
lstmt = s
}
- stmtBranches(s.Stmt)
+ stmtBranches(lstmt, s.Stmt)
case *ast.BranchStmt:
if s.Label == nil {
blockBranches(lstmt, s.List)
case *ast.IfStmt:
- stmtBranches(s.Body)
+ stmtBranches(lstmt, s.Body)
if s.Else != nil {
- stmtBranches(s.Else)
+ stmtBranches(lstmt, s.Else)
}
case *ast.CaseClause:
blockBranches(nil, s.Body)
case *ast.SwitchStmt:
- stmtBranches(s.Body)
+ stmtBranches(lstmt, s.Body)
case *ast.TypeSwitchStmt:
- stmtBranches(s.Body)
+ stmtBranches(lstmt, s.Body)
case *ast.CommClause:
blockBranches(nil, s.Body)
case *ast.SelectStmt:
- stmtBranches(s.Body)
+ stmtBranches(lstmt, s.Body)
case *ast.ForStmt:
- stmtBranches(s.Body)
+ stmtBranches(lstmt, s.Body)
case *ast.RangeStmt:
- stmtBranches(s.Body)
+ stmtBranches(lstmt, s.Body)
}
}
for _, s := range list {
- stmtBranches(s)
+ stmtBranches(nil, s)
}
return fwdJumps
--- /dev/null
+// 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.
+
+package p
+
+func _() {
+outer:
+inner:
+ for {
+ continue inner
+ break inner
+ }
+ goto outer
+}
+
+func _() {
+outer:
+inner:
+ for {
+ continue inner
+ continue outer /* ERROR "invalid continue label outer" */
+ break outer /* ERROR "invalid break label outer" */
+ }
+ goto outer
+}
--- /dev/null
+// 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.
+
+package p
+
+func _() {
+outer:
+ for {
+ break outer
+ }
+
+ for {
+ break outer /* ERROR "invalid break label outer" */
+ }
+}
+
+func _() {
+outer:
+ for {
+ continue outer
+ }
+
+ for {
+ continue outer /* ERROR "invalid continue label outer" */
+ }
+}