aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/errors.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2020-09-11 14:23:34 -0400
committerRob Findley <rfindley@google.com>2020-09-11 14:23:34 -0400
commitf8b1c17aced24a1618c6984794be9770c5d260be (patch)
tree45af8d39b5c3d9f43d439ebec0a2ba42b49efe70 /src/go/types/errors.go
parente5d91ab096a9ff9673311f1a7f3f860a7f9c2062 (diff)
parent07c1788357cfe6a4ee5f6f6a54d4fe9f579fa844 (diff)
downloadgo-dev.types.tar.gz
go-dev.types.zip
[dev.types] all: merge master into dev.typesdev.types
Change-Id: Ia6964cb4e09153c15cc9c5b441373d1b3cb8f757
Diffstat (limited to 'src/go/types/errors.go')
-rw-r--r--src/go/types/errors.go39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/go/types/errors.go b/src/go/types/errors.go
index 91b077163c..88e41c5713 100644
--- a/src/go/types/errors.go
+++ b/src/go/types/errors.go
@@ -7,6 +7,7 @@
package types
import (
+ "errors"
"fmt"
"go/ast"
"go/token"
@@ -72,22 +73,33 @@ func (check *Checker) dump(format string, args ...interface{}) {
fmt.Println(check.sprintf(format, args...))
}
-func (check *Checker) err(pos token.Pos, msg string, soft bool) {
+func (check *Checker) err(err error) {
+ if err == nil {
+ return
+ }
+ var e Error
+ isInternal := errors.As(err, &e)
// Cheap trick: Don't report errors with messages containing
// "invalid operand" or "invalid type" as those tend to be
// follow-on errors which don't add useful information. Only
// exclude them if these strings are not at the beginning,
// and only if we have at least one error already reported.
- if check.firstErr != nil && (strings.Index(msg, "invalid operand") > 0 || strings.Index(msg, "invalid type") > 0) {
+ isInvalidErr := isInternal && (strings.Index(e.Msg, "invalid operand") > 0 || strings.Index(e.Msg, "invalid type") > 0)
+ if check.firstErr != nil && isInvalidErr {
return
}
- err := Error{check.fset, pos, msg, soft}
if check.firstErr == nil {
check.firstErr = err
}
if trace {
+ pos := e.Pos
+ msg := e.Msg
+ if !isInternal {
+ msg = err.Error()
+ pos = token.NoPos
+ }
check.trace(pos, "ERROR: %s", msg)
}
@@ -99,15 +111,30 @@ func (check *Checker) err(pos token.Pos, msg string, soft bool) {
}
func (check *Checker) error(pos token.Pos, msg string) {
- check.err(pos, msg, false)
+ check.err(Error{Fset: check.fset, Pos: pos, Msg: msg})
+}
+
+// newErrorf creates a new Error, but does not handle it.
+func (check *Checker) newErrorf(pos token.Pos, format string, args ...interface{}) error {
+ return Error{
+ Fset: check.fset,
+ Pos: pos,
+ Msg: check.sprintf(format, args...),
+ Soft: false,
+ }
}
func (check *Checker) errorf(pos token.Pos, format string, args ...interface{}) {
- check.err(pos, check.sprintf(format, args...), false)
+ check.error(pos, check.sprintf(format, args...))
}
func (check *Checker) softErrorf(pos token.Pos, format string, args ...interface{}) {
- check.err(pos, check.sprintf(format, args...), true)
+ check.err(Error{
+ Fset: check.fset,
+ Pos: pos,
+ Msg: check.sprintf(format, args...),
+ Soft: true,
+ })
}
func (check *Checker) invalidAST(pos token.Pos, format string, args ...interface{}) {