mirror of
https://github.com/golang/go
synced 2024-11-27 01:21:18 -07:00
[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 <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
91803a2df3
commit
df58f3368e
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user