1
0
mirror of https://github.com/golang/go synced 2024-09-29 22:24:33 -06:00

internal/types/errors: export error codes

Adjust self-test accordingly.

Change-Id: I69987a306760da9eaf832275af0e9a8b6131a349
Reviewed-on: https://go-review.googlesource.com/c/go/+/439561
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2022-10-06 14:08:14 -07:00 committed by Gopher Robot
parent b440c15db7
commit 49372957ab
2 changed files with 295 additions and 300 deletions

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,7 @@ func walkCodes(t *testing.T, f func(string, int, *ast.ValueSpec)) {
continue
}
obj := info.ObjectOf(spec.Names[0])
if named, ok := obj.Type().(*Named); ok && named.Obj().Name() == "errorCode" {
if named, ok := obj.Type().(*Named); ok && named.Obj().Name() == "Code" {
if len(spec.Names) != 1 {
t.Fatalf("bad Code declaration for %q: got %d names, want exactly 1", spec.Names[0].Name, len(spec.Names))
}
@ -154,13 +154,8 @@ func TestErrorCodeStyle(t *testing.T) {
if len(name) > len(longestName) {
longestName = name
}
if token.IsExported(name) {
// This is an experimental API, and errorCode values should not be
// exported.
t.Errorf("%q is exported", name)
}
if name[0] != '_' || !token.IsExported(name[1:]) {
t.Errorf("%q should start with _, followed by an exported identifier", name)
if !token.IsExported(name) {
t.Errorf("%q is not exported", name)
}
lower := strings.ToLower(name)
for _, bad := range forbiddenInIdent {