]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: add Config.IgnoreBranches flag
authorRobert Griesemer <gri@golang.org>
Tue, 1 Dec 2020 20:18:20 +0000 (12:18 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 1 Dec 2020 21:49:40 +0000 (21:49 +0000)
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>

src/cmd/compile/internal/gc/noder.go
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/stmt.go
test/run.go

index 1cdb6bc08cf274d65da6c4e2397a77e630bbcee2..5115932b1e407de44dc02ceb89c82781135e1395 100644 (file)
@@ -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' {
index a40665ee17ffa572a780c0d98e9b278c6182eb8d..c5c30babff671649d1c5c472a7e8663af6f95731 100644 (file)
@@ -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.
index 37aa3c730856ba890e14296c3002e0bc5b8c0643..11a9b8313f3c36dde70c9843fdcdb422ff135892 100644 (file)
@@ -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)
                }
index 319aed5ac1dc35bf4ecf75ed739fe0428ac13ec1..1eef6f1f35bd2001eea58274205120bc1662cd57 100644 (file)
@@ -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",