diff options
author | Robert Griesemer <gri@golang.org> | 2021-02-25 14:54:04 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-03-10 00:50:17 +0000 |
commit | acd7cb5887f486558fbcd517ed636a96447d695d (patch) | |
tree | bec05bc95acba47b91ddd0f381e328fce9313fd4 /src/cmd/compile/internal/types2/initorder.go | |
parent | 142a76530cf610fe02d151727fa0d8038c552127 (diff) | |
download | go-acd7cb5887f486558fbcd517ed636a96447d695d.tar.gz go-acd7cb5887f486558fbcd517ed636a96447d695d.zip |
cmd/compile/internal/types2: better error reporting framework (starting point)
Until now, errors which came with additional details (e.g., a declaration
cycle error followed by the list of objects involved in the cycle, one per
line) were reported as an ordinary error followed by "secondary" errors,
with the secondary errors marked as such by having a tab-indented error
message.
This approach often required clients to filter these secondary errors
(as they are not new errors, they are just clarifying a previously
reported error).
This CL introduces a new internal error_ type which permits accumulating
various error information that may then be reported as a single error.
Change-Id: I25b2f094facd37e12737e517f7ef8853d465ff77
Reviewed-on: https://go-review.googlesource.com/c/go/+/296689
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/initorder.go')
-rw-r--r-- | src/cmd/compile/internal/types2/initorder.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/types2/initorder.go b/src/cmd/compile/internal/types2/initorder.go index a9cabecdf2..4081627666 100644 --- a/src/cmd/compile/internal/types2/initorder.go +++ b/src/cmd/compile/internal/types2/initorder.go @@ -151,18 +151,20 @@ func findPath(objMap map[Object]*declInfo, from, to Object, seen map[Object]bool // reportCycle reports an error for the given cycle. func (check *Checker) reportCycle(cycle []Object) { obj := cycle[0] + var err error_ if check.conf.CompilerErrorMessages { - check.errorf(obj, "initialization loop for %s", obj.Name()) + err.errorf(obj, "initialization loop for %s", obj.Name()) } else { - check.errorf(obj, "initialization cycle for %s", obj.Name()) + err.errorf(obj, "initialization cycle for %s", obj.Name()) } // subtle loop: print cycle[i] for i = 0, n-1, n-2, ... 1 for len(cycle) = n for i := len(cycle) - 1; i >= 0; i-- { - check.errorf(obj, "\t%s refers to", obj.Name()) // secondary error, \t indented + err.errorf(obj, "%s refers to", obj.Name()) obj = cycle[i] } // print cycle[0] again to close the cycle - check.errorf(obj, "\t%s", obj.Name()) + err.errorf(obj, "%s", obj.Name()) + check.report(&err) } // ---------------------------------------------------------------------------- |