diff options
author | Robert Griesemer <gri@golang.org> | 2021-01-21 20:20:22 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-01-22 06:02:32 +0000 |
commit | f8654579cdd637167bb38d38f0de76abc812d34c (patch) | |
tree | c8e390719f9f6b1dc132a0aa1fc468b509bf09c7 /src/cmd/compile/internal/types2/stmt.go | |
parent | 18bd7aa62581f313c86164d763b1e246307888a9 (diff) | |
download | go-f8654579cdd637167bb38d38f0de76abc812d34c.tar.gz go-f8654579cdd637167bb38d38f0de76abc812d34c.zip |
[dev.typeparams] cmd/compile/internal/types2: adjust errors in branch checking code, fix a bug
The types2.Config.IgnoreBranches flag mistakenly excluded a
set of label-unrelated branch checks. After fixing this and
also adjusting some error messages to match the existing
compiler errors, more errorcheck tests pass now with the -G
option.
Renamed IngnoreBranches to IgnoreLabels since its controlling
label checks, not all branch statement (such as continue, etc)
checks.
Change-Id: I0819f56eb132ce76c9a9628d8942af756691065a
Reviewed-on: https://go-review.googlesource.com/c/go/+/285652
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/stmt.go')
-rw-r--r-- | src/cmd/compile/internal/types2/stmt.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index cbfe97b03c..ca0abcd10c 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -41,8 +41,7 @@ func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body check.stmtList(0, body.List) - if check.hasLabel { - assert(!check.conf.IgnoreBranches) + if check.hasLabel && !check.conf.IgnoreLabels { check.labels(body) } @@ -321,7 +320,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) { check.declStmt(s.DeclList) case *syntax.LabeledStmt: - check.hasLabel = !check.conf.IgnoreBranches + check.hasLabel = true check.stmt(ctxt, s.Stmt) case *syntax.ExprStmt: @@ -446,22 +445,26 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) { } case *syntax.BranchStmt: - if check.conf.IgnoreBranches { - break - } - if s.Label != nil { check.hasLabel = true - return // checked in 2nd pass (check.labels) + break // checked in 2nd pass (check.labels) } switch s.Tok { case syntax.Break: if ctxt&breakOk == 0 { - check.error(s, "break not in for, switch, or select statement") + if check.conf.CompilerErrorMessages { + check.error(s, "break is not in a loop, switch, or select statement") + } else { + check.error(s, "break not in for, switch, or select statement") + } } case syntax.Continue: if ctxt&continueOk == 0 { - check.error(s, "continue not in for statement") + if check.conf.CompilerErrorMessages { + check.error(s, "continue is not in a loop") + } else { + check.error(s, "continue not in for statement") + } } case syntax.Fallthrough: if ctxt&fallthroughOk == 0 { |