From: Robert Griesemer Date: Thu, 10 Dec 2020 03:15:15 +0000 (-0800) Subject: [dev.typeparams] cmd/compile/internal/types2: don't report two errors for bad strings X-Git-Tag: go1.17beta1~1473^2~160 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=df58f3368e;p=gostls13.git [dev.typeparams] cmd/compile/internal/types2: don't report two errors for bad strings If the parser reported an error for (string) literals, don't report a second error during type checking. This should have a couple of tests but they are tricky to arrange with the current testing framework as the ERROR comment cannot be on the line where the string. But the change is straightforward and we have test/fixedbugs/issue32133.go that is passing now. Change-Id: I0cd7f002b04e4092b8eb66009c7413288c8bfb23 Reviewed-on: https://go-review.googlesource.com/c/go/+/277993 Trust: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Go Bot --- diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index 252d4814cc..34cbefc864 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -1188,7 +1188,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin case *syntax.BasicLit: if e.Bad { - goto Error // error was reported before + goto Error // error reported during parsing } x.setConst(e.Kind, e.Value) if x.mode == invalid { diff --git a/src/cmd/compile/internal/types2/resolver.go b/src/cmd/compile/internal/types2/resolver.go index 5cd0a3e198..b57b41e2b0 100644 --- a/src/cmd/compile/internal/types2/resolver.go +++ b/src/cmd/compile/internal/types2/resolver.go @@ -236,6 +236,9 @@ func (check *Checker) collectObjects() { switch s := decl.(type) { case *syntax.ImportDecl: // import package + if s.Path.Bad { + continue // error reported during parsing + } path, err := validatedImportPath(s.Path.Value) if err != nil { check.errorf(s.Path, "invalid import path (%s)", err) diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index 39bb3a6b14..22df01b3be 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -1045,7 +1045,8 @@ func (a byUniqueMethodName) Less(i, j int) bool { return a[i].Id() < a[j].Id() } func (a byUniqueMethodName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (check *Checker) tag(t *syntax.BasicLit) string { - if t != nil { + // If t.Bad, an error was reported during parsing. + if t != nil && !t.Bad { if t.Kind == syntax.StringLit { if val, err := strconv.Unquote(t.Value); err == nil { return val diff --git a/test/run.go b/test/run.go index 91bdd629bf..b6c9d6050c 100644 --- a/test/run.go +++ b/test/run.go @@ -2014,7 +2014,6 @@ var excluded = map[string]bool{ "fixedbugs/issue28079b.go": true, // types2 reports follow-on errors "fixedbugs/issue28268.go": true, // types2 reports follow-on errors "fixedbugs/issue31747.go": true, // types2 is missing support for -lang flag - "fixedbugs/issue32133.go": true, // types2 line numbers off? "fixedbugs/issue33460.go": true, // types2 reports alternative positions in separate error "fixedbugs/issue34329.go": true, // types2 is missing support for -lang flag "fixedbugs/issue41575.go": true, // types2 reports alternative positions in separate error @@ -2023,7 +2022,7 @@ var excluded = map[string]bool{ "fixedbugs/issue4232.go": true, // types2 reports (correct) extra errors "fixedbugs/issue4452.go": true, // types2 reports (correct) extra errors "fixedbugs/issue5609.go": true, // types2 needs a better error message - "fixedbugs/issue6500.go": true, // compiler -G is not reporting an error (but types2 does) + "fixedbugs/issue6500.go": true, // error reported by noder (not running for types2 errorcheck test) "fixedbugs/issue6889.go": true, // types2 can handle this without constant overflow "fixedbugs/issue7525.go": true, // types2 reports init cycle error on different line - ok otherwise "fixedbugs/issue7525b.go": true, // types2 reports init cycle error on different line - ok otherwise