aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/jsontext
diff options
context:
space:
mode:
authorJulien Cretel <jub0bsinthecloud@gmail.com>2025-10-01 20:08:18 +0000
committerGopher Robot <gobot@golang.org>2025-10-13 10:12:48 -0700
commit6bcd97d9f4386528aa85eb3cc27da0ed902de870 (patch)
tree54acec806440b95e7afc493d42b0b095fdaee1a5 /src/encoding/json/jsontext
parent1cd71689f2ed8f07031a0cc58fc3586ca501839f (diff)
downloadgo-6bcd97d9f4386528aa85eb3cc27da0ed902de870.tar.xz
all: replace calls to errors.As with errors.AsType
This change replaces most occurrences (in code as well as in comments) of errors.As with errors.AsType. It leaves the errors package and vendored code untouched. Change-Id: I3bde73f318a0b408bdb8f5a251494af15a13118a GitHub-Last-Rev: 8aaaa36a5a12d2a6a90c6d51680464e1a3115139 GitHub-Pull-Request: golang/go#75698 Reviewed-on: https://go-review.googlesource.com/c/go/+/708495 Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/encoding/json/jsontext')
-rw-r--r--src/encoding/json/jsontext/coder_test.go2
-rw-r--r--src/encoding/json/jsontext/fuzz_test.go7
-rw-r--r--src/encoding/json/jsontext/state.go3
3 files changed, 6 insertions, 6 deletions
diff --git a/src/encoding/json/jsontext/coder_test.go b/src/encoding/json/jsontext/coder_test.go
index 4a9efb3b8f..8602e3e7ff 100644
--- a/src/encoding/json/jsontext/coder_test.go
+++ b/src/encoding/json/jsontext/coder_test.go
@@ -486,7 +486,7 @@ func testCoderInterleaved(t *testing.T, where jsontest.CasePos, modeName string,
// Retry as a ReadToken call.
expectError := dec.PeekKind() == '}' || dec.PeekKind() == ']'
if expectError {
- if !errors.As(err, new(*SyntacticError)) {
+ if _, ok := errors.AsType[*SyntacticError](err); !ok {
t.Fatalf("%s: Decoder.ReadToken error is %T, want %T", where, err, new(SyntacticError))
}
tickTock = !tickTock
diff --git a/src/encoding/json/jsontext/fuzz_test.go b/src/encoding/json/jsontext/fuzz_test.go
index 60d16b9e27..3ad181d434 100644
--- a/src/encoding/json/jsontext/fuzz_test.go
+++ b/src/encoding/json/jsontext/fuzz_test.go
@@ -53,9 +53,10 @@ func FuzzCoder(f *testing.F) {
} else {
val, err := dec.ReadValue()
if err != nil {
- expectError := dec.PeekKind() == '}' || dec.PeekKind() == ']'
- if expectError && errors.As(err, new(*SyntacticError)) {
- continue
+ if expectError := dec.PeekKind() == '}' || dec.PeekKind() == ']'; expectError {
+ if _, ok := errors.AsType[*SyntacticError](err); ok {
+ continue
+ }
}
if err == io.EOF {
break
diff --git a/src/encoding/json/jsontext/state.go b/src/encoding/json/jsontext/state.go
index d214fd5190..538dfe32bf 100644
--- a/src/encoding/json/jsontext/state.go
+++ b/src/encoding/json/jsontext/state.go
@@ -24,8 +24,7 @@ import (
// The name of a duplicate JSON object member can be extracted as:
//
// err := ...
-// var serr jsontext.SyntacticError
-// if errors.As(err, &serr) && serr.Err == jsontext.ErrDuplicateName {
+// if serr, ok := errors.AsType[jsontext.SyntacticError](err); ok && serr.Err == jsontext.ErrDuplicateName {
// ptr := serr.JSONPointer // JSON pointer to duplicate name
// name := ptr.LastToken() // duplicate name itself
// ...