aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/errors.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-03-11 16:34:01 -0800
committerRobert Griesemer <gri@golang.org>2021-03-13 00:38:58 +0000
commit16ad1ea8417bb842204bf7c982e3f19969b67458 (patch)
tree60e0ca42041744743a37134d821cf735a8c16189 /src/cmd/compile/internal/types2/errors.go
parent7b47f9a5f2092dcbc1546304f1f1b739883fa4c4 (diff)
downloadgo-16ad1ea8417bb842204bf7c982e3f19969b67458.tar.gz
go-16ad1ea8417bb842204bf7c982e3f19969b67458.zip
cmd/compile/internal/types2: simplify error reporting API (cleanup)
- Remove specialized errorf functions for invalid AST/argument/operation. Instead use prefix constants with the error message. - Replace several calls to Checker.errorf with calls to Checker.error if there are no arguments to format. - Replace a handful of %s format verbs with %v to satisfy vet check. - Add a basic test that checks that we're not using Checker.errorf when we should be using Checker.error. Change-Id: I7bc7c14f3cf774689ec8cd5782ea31b6e30dbcd6 Reviewed-on: https://go-review.googlesource.com/c/go/+/300995 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/errors.go')
-rw-r--r--src/cmd/compile/internal/types2/errors.go28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/cmd/compile/internal/types2/errors.go b/src/cmd/compile/internal/types2/errors.go
index 01df50c8e3..79fedc91e1 100644
--- a/src/cmd/compile/internal/types2/errors.go
+++ b/src/cmd/compile/internal/types2/errors.go
@@ -142,7 +142,7 @@ func (check *Checker) dump(format string, args ...interface{}) {
fmt.Println(check.sprintf(format, args...))
}
-func (check *Checker) err(pos syntax.Pos, msg string, soft bool) {
+func (check *Checker) err(at poser, msg string, soft bool) {
// 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
@@ -152,6 +152,8 @@ func (check *Checker) err(pos syntax.Pos, msg string, soft bool) {
return
}
+ pos := posFor(at)
+
// If we are encountering an error while evaluating an inherited
// constant initialization expression, pos is the position of in
// the original expression, and not of the currently declared
@@ -179,32 +181,26 @@ func (check *Checker) err(pos syntax.Pos, msg string, soft bool) {
f(err)
}
+const (
+ invalidAST = "invalid AST: "
+ invalidArg = "invalid argument: "
+ invalidOp = "invalid operation: "
+)
+
type poser interface {
Pos() syntax.Pos
}
func (check *Checker) error(at poser, msg string) {
- check.err(posFor(at), msg, false)
+ check.err(at, msg, false)
}
func (check *Checker) errorf(at poser, format string, args ...interface{}) {
- check.err(posFor(at), check.sprintf(format, args...), false)
+ check.err(at, check.sprintf(format, args...), false)
}
func (check *Checker) softErrorf(at poser, format string, args ...interface{}) {
- check.err(posFor(at), check.sprintf(format, args...), true)
-}
-
-func (check *Checker) invalidASTf(at poser, format string, args ...interface{}) {
- check.errorf(at, "invalid AST: "+format, args...)
-}
-
-func (check *Checker) invalidArgf(at poser, format string, args ...interface{}) {
- check.errorf(at, "invalid argument: "+format, args...)
-}
-
-func (check *Checker) invalidOpf(at poser, format string, args ...interface{}) {
- check.errorf(at, "invalid operation: "+format, args...)
+ check.err(at, check.sprintf(format, args...), true)
}
// posFor reports the left (= start) position of at.