You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current errors.As usage is non-sensical. In so much as we have to use two different functions already, the fact the following code will compile and fail despite looking right is madness:
But...why? errors is already using reflection to identify types here, and when we evaluate the first from we correctly deduce that err is *ErrNew - the problem is we convert targetType into ErrNew and then check for assignability....which obviously doesn't work because a pointer can't be assigned to a concrete struct which is the type we're comparing to now.
Basically why is As setup such that this very obvious way of using it doesn't work:
err:=&ErrorNew{}
errors.As(err, &ErrNew{})
EDIT: I acknowledge there might be very good reasons this was done this way, but from an ergonomics perspective it's a disaster that Go will happily compile this and it will not work at all how you would expect - plus it's a lot of noise for those wanting to use typed errors.
The text was updated successfully, but these errors were encountered:
Proposal Details
The current
errors.As
usage is non-sensical. In so much as we have to use two different functions already, the fact the following code will compile and fail despite looking right is madness:The correct code is of course this:
But...why?
errors
is already using reflection to identify types here, and when we evaluate the first from we correctly deduce thaterr
is*ErrNew
- the problem is we converttargetType
intoErrNew
and then check for assignability....which obviously doesn't work because a pointer can't be assigned to a concrete struct which is the type we're comparing to now.Basically why is
As
setup such that this very obvious way of using it doesn't work:EDIT: I acknowledge there might be very good reasons this was done this way, but from an ergonomics perspective it's a disaster that Go will happily compile this and it will not work at all how you would expect - plus it's a lot of noise for those wanting to use typed errors.
The text was updated successfully, but these errors were encountered: