mirror of
https://github.com/golang/go
synced 2024-11-26 16:16:57 -07:00
[dev.typeparams] cmd/compile/internal/types2: add Config.IgnoreBranches flag
If the new Config.IgnoreBranches flag is set, the typechecker ignores errors due to misplaced labels, break, continue, fallthrough, or goto statements. Since the syntax parser already checks these errors, we need to disable a 2nd check by the typechecker to avoid duplicate errors when running the compiler with the new typechecker. Adjusted test/run.go to not ignore some of the tests that used to fail because of duplicate errors. Change-Id: I8756eb1d44f67afef5e57da289cd604b8e1716db Reviewed-on: https://go-review.googlesource.com/c/go/+/274612 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
72ad2f44ea
commit
bdc4ffe9a8
@ -84,7 +84,8 @@ func parseFiles(filenames []string, allowGenerics bool) (lines uint) {
|
||||
|
||||
conf := types2.Config{
|
||||
InferFromConstraints: true,
|
||||
CompilerErrorMessages: true,
|
||||
IgnoreBranches: true, // parser already checked via syntax.CheckBranches mode
|
||||
CompilerErrorMessages: true, // use error strings matching existing compiler errors
|
||||
Error: func(err error) {
|
||||
terr := err.(types2.Error)
|
||||
if len(terr.Msg) > 0 && terr.Msg[0] == '\t' {
|
||||
|
@ -119,6 +119,11 @@ type Config struct {
|
||||
// Do not use casually!
|
||||
FakeImportC bool
|
||||
|
||||
// If IgnoreBranches is set, errors related to incorrectly placed
|
||||
// labels, gotos, break, continue, and fallthrough statements are
|
||||
// ignored.
|
||||
IgnoreBranches bool
|
||||
|
||||
// If CompilerErrorMessages is set, errors are reported using
|
||||
// cmd/compile error strings to match $GOROOT/test errors.
|
||||
// TODO(gri) Consolidate error messages and remove this flag.
|
||||
|
@ -42,6 +42,7 @@ func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body
|
||||
check.stmtList(0, body.List)
|
||||
|
||||
if check.hasLabel {
|
||||
assert(!check.conf.IgnoreBranches)
|
||||
check.labels(body)
|
||||
}
|
||||
|
||||
@ -316,7 +317,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
|
||||
check.declStmt(s.DeclList)
|
||||
|
||||
case *syntax.LabeledStmt:
|
||||
check.hasLabel = true
|
||||
check.hasLabel = !check.conf.IgnoreBranches
|
||||
check.stmt(ctxt, s.Stmt)
|
||||
|
||||
case *syntax.ExprStmt:
|
||||
@ -443,6 +444,10 @@ 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)
|
||||
@ -464,6 +469,9 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
|
||||
}
|
||||
check.error(s, msg)
|
||||
}
|
||||
case syntax.Goto:
|
||||
// goto's must have labels, should have been caught above
|
||||
fallthrough
|
||||
default:
|
||||
check.invalidASTf(s, "branch statement: %s", s.Tok)
|
||||
}
|
||||
|
@ -771,15 +771,12 @@ func (t *test) run() {
|
||||
"func1.go",
|
||||
"funcdup.go",
|
||||
"funcdup2.go",
|
||||
"goto.go",
|
||||
"import1.go",
|
||||
"import5.go",
|
||||
"import6.go",
|
||||
"init.go",
|
||||
"initializerr.go",
|
||||
"initloop.go",
|
||||
"label.go",
|
||||
"label1.go",
|
||||
"makechan.go",
|
||||
"makemap.go",
|
||||
"makenew.go",
|
||||
@ -792,6 +789,7 @@ func (t *test) run() {
|
||||
"shift1.go",
|
||||
"slice3err.go",
|
||||
"switch3.go",
|
||||
"switch4.go",
|
||||
"switch5.go",
|
||||
"switch6.go",
|
||||
"switch7.go",
|
||||
|
Loading…
Reference in New Issue
Block a user