]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: don't report two errors for bad strings
authorRobert Griesemer <gri@golang.org>
Thu, 10 Dec 2020 03:15:15 +0000 (19:15 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 14 Dec 2020 21:27:49 +0000 (21:27 +0000)
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 <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/resolver.go
src/cmd/compile/internal/types2/typexpr.go
test/run.go

index 252d4814cc3ad153141d53eab5ff80e1dcde898b..34cbefc864b75e5f5e59622cc2cd6ec1d553b79e 100644 (file)
@@ -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 {
index 5cd0a3e1987560b663a9b82795bbc69bdfe8683a..b57b41e2b098df5b0e16af35eee39cae0af8d4d0 100644 (file)
@@ -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)
index 39bb3a6b146429237736d08674911d2e31b20bf0..22df01b3bea2f367297decba3e259fcc47cecce4 100644 (file)
@@ -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
index 91bdd629bfe77a16db40c7a14946950562b6b347..b6c9d6050cfb133b9e133452e5ccc4fc6e656679 100644 (file)
@@ -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