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>
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' {
// 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.
check.stmtList(0, body.List)
if check.hasLabel {
+ assert(!check.conf.IgnoreBranches)
check.labels(body)
}
check.declStmt(s.DeclList)
case *syntax.LabeledStmt:
- check.hasLabel = true
+ check.hasLabel = !check.conf.IgnoreBranches
check.stmt(ctxt, s.Stmt)
case *syntax.ExprStmt:
}
case *syntax.BranchStmt:
+ if check.conf.IgnoreBranches {
+ break
+ }
+
if s.Label != nil {
check.hasLabel = true
return // checked in 2nd pass (check.labels)
}
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)
}
"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",
"shift1.go",
"slice3err.go",
"switch3.go",
+ "switch4.go",
"switch5.go",
"switch6.go",
"switch7.go",