From a846bb0aa523c8781248161b63bc2ab6a245cec1 Mon Sep 17 00:00:00 2001 From: Julien Cretel Date: Mon, 29 Sep 2025 16:57:53 +0000 Subject: errors: add AsType Fixes #51945 Change-Id: Icda169782e796578eba728938134a85b5827d3b6 GitHub-Last-Rev: c6ff335ee1ffb6b7975141795a4632a55247299d GitHub-Pull-Request: golang/go#75621 Reviewed-on: https://go-review.googlesource.com/c/go/+/707235 Reviewed-by: Carlos Amedee Reviewed-by: Damien Neil LUCI-TryBot-Result: Go LUCI Reviewed-by: Sean Liao --- src/errors/errors.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/errors/errors.go') diff --git a/src/errors/errors.go b/src/errors/errors.go index 5059be12ed..8b926cfe14 100644 --- a/src/errors/errors.go +++ b/src/errors/errors.go @@ -41,12 +41,12 @@ // // because the former will succeed if err wraps [io/fs.ErrExist]. // -// [As] examines the tree of its first argument looking for an error that can be -// assigned to its second argument, which must be a pointer. If it succeeds, it -// performs the assignment and returns true. Otherwise, it returns false. The form +// [AsType] examines the tree of its argument looking for an error whose +// type matches its type argument. If it succeeds, it returns the +// corresponding value of that type and true. Otherwise, it returns the +// zero value of that type and false. The form // -// var perr *fs.PathError -// if errors.As(err, &perr) { +// if perr, ok := errors.AsType[*fs.PathError](err); ok { // fmt.Println(perr.Path) // } // -- cgit v1.3