errors: do not call Elem() twice

This commit is contained in:
Vitaly Zdanevich 2021-03-08 05:54:42 +03:00
parent 597b5d192e
commit 644d479a27
1 changed files with 2 additions and 2 deletions

View File

@ -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))