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/stmt.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/stmt.go')
-rw-r--r-- | src/cmd/compile/internal/types2/stmt.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index 490cd0fc19..21244f6065 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -253,8 +253,10 @@ L: // (quadratic algorithm, but these lists tend to be very short) for _, vt := range seen[val] { if check.identical(v.typ, vt.typ) { - check.errorf(&v, "duplicate case %s in expression switch", &v) - check.error(vt.pos, "\tprevious case") // secondary error, \t indented + var err error_ + err.errorf(&v, "duplicate case %s in expression switch", &v) + err.errorf(vt.pos, "previous case") + check.report(&err) continue L } } @@ -282,8 +284,10 @@ L: if T != nil { Ts = T.String() } - check.errorf(e, "duplicate case %s in type switch", Ts) - check.error(pos, "\tprevious case") // secondary error, \t indented + var err error_ + err.errorf(e, "duplicate case %s in type switch", Ts) + err.errorf(pos, "previous case") + check.report(&err) continue L } } @@ -430,8 +434,10 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) { // with the same name as a result parameter is in scope at the place of the return." for _, obj := range res.vars { if alt := check.lookup(obj.name); alt != nil && alt != obj { - check.errorf(s, "result parameter %s not in scope at return", obj.name) - check.errorf(alt, "\tinner declaration of %s", obj) + var err error_ + err.errorf(s, "result parameter %s not in scope at return", obj.name) + err.errorf(alt, "inner declaration of %s", obj) + check.report(&err) // ok to continue } } |