From fedb49487831e1168ebad7d313e23a8494bee6a2 Mon Sep 17 00:00:00 2001 From: Vitaly Zdanevich Date: Mon, 8 Mar 2021 03:15:25 +0000 Subject: [PATCH] errors/wrap: do not call Elem() twice Change-Id: I2fe6037c45a0dfe25f946a92ff97b5e3fbd69bc0 GitHub-Last-Rev: 644d479a27c0eccfc0b37e1a560ca09e47b5a972 GitHub-Pull-Request: golang/go#44851 Reviewed-on: https://go-review.googlesource.com/c/go/+/299629 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Tobias Klauser --- src/errors/wrap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/errors/wrap.go b/src/errors/wrap.go index 7928fe673e..4eb4f9ae37 100644 --- a/src/errors/wrap.go +++ b/src/errors/wrap.go @@ -83,10 +83,10 @@ func As(err error, target interface{}) bool { if typ.Kind() != reflectlite.Ptr || val.IsNil() { panic("errors: target must be a non-nil pointer") } - if e := typ.Elem(); e.Kind() != reflectlite.Interface && !e.Implements(errorType) { + targetType := typ.Elem() + if targetType.Kind() != reflectlite.Interface && !targetType.Implements(errorType) { panic("errors: *target must be interface or implement error") } - targetType := typ.Elem() for err != nil { if reflectlite.TypeOf(err).AssignableTo(targetType) { val.Elem().Set(reflectlite.ValueOf(err))