]> Cypherpunks.ru repositories - gostls13.git/commit
go/types: add internal error codes
authorRob Findley <rfindley@google.com>
Mon, 19 Oct 2020 15:51:17 +0000 (11:51 -0400)
committerRobert Findley <rfindley@google.com>
Fri, 30 Oct 2020 14:13:03 +0000 (14:13 +0000)
commit733c4af41d2e89d18cfb039e0107336a4c1ec220
treedd690132c110447b802de7b1b08c89635df192ca
parentf7e26467b4e7ee0bb3219c26e71292ff4aac7da9
go/types: add internal error codes

Tools using go/types sometimes need to implement special handling for
certain errors produced by the type-checker. They can offer suggested
fixes, expand the error position to surrounding syntax, highlight
related syntax (for example in the case of a declaration cycle), link to
additional documentation, group errors by category, or correlate errors
with signals produced by other static analysis tools.

All these require a notion of error identity. Tools need to be able to
reliably determine the nature of an error without re-implementing type
checking logic or parsing error messages. This CL is a first-pass at
adding such an identifier to types.Error: a (for the moment unexported)
field containing one of many declared errorCode constants.

A wide variety of error code constants are defined, and assigned to type
checker errors according to their 'functional equivalence', meaning that
they should be ideally be stable under refactoring.

With few exceptions, each error code is documented with an example that
produces it. This is enforced by tests.

When error codes are exported they will represent quite a large API
surface. For this reason, as well as the likelihood that error codes
will change at the start, both the code field and the codes themselves
are initially unexported. gopls will read these fields using reflection
during this experimental phase. Others can obviously do the same,
provided they accept the lack of forward compatibility.

For #42290

Change-Id: I15e3c2bffd2046c20297b1857057d421f633098a
Reviewed-on: https://go-review.googlesource.com/c/go/+/264179
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
21 files changed:
src/go/types/api.go
src/go/types/assignments.go
src/go/types/builtins.go
src/go/types/call.go
src/go/types/check.go
src/go/types/check_test.go
src/go/types/conversions.go
src/go/types/decl.go
src/go/types/errorcodes.go [new file with mode: 0644]
src/go/types/errorcodes_test.go [new file with mode: 0644]
src/go/types/errors.go
src/go/types/expr.go
src/go/types/initorder.go
src/go/types/labels.go
src/go/types/operand.go
src/go/types/resolver.go
src/go/types/self_test.go
src/go/types/stmt.go
src/go/types/testdata/cycles.src
src/go/types/testdata/expr3.src
src/go/types/typexpr.go