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
I have a custom error (implementing the Error interface). I have a function that calls two functions; the first function returns a nil error and and the second returns nil for my custom error. If I call the first function and assign it to err and then I call the second and accidentally assign it to the same err variable; a nil check always seems to return true.
I am unsure if this is expected or not, but it took me quite a while to track down exactly why my code was behaving weirdly. I realise it was a mistake on my behalf for assigning my custom error to an error type variable, but since the compiler seemed happy I didn't realise I was doing anything wrong.
What did you expect to see?
That all nil checks return the correct result.
What did you see instead?
A nil check on a custom error type always returns true.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a custom error (implementing the
Error
interface). I have a function that calls two functions; the first function returns a nilerror
and and the second returns nil for my custom error. If I call the first function and assign it toerr
and then I call the second and accidentally assign it to the sameerr
variable; a nil check always seems to return true.https://play.golang.org/p/4edPo-lMy6G
I am unsure if this is expected or not, but it took me quite a while to track down exactly why my code was behaving weirdly. I realise it was a mistake on my behalf for assigning my custom error to an
error
type variable, but since the compiler seemed happy I didn't realise I was doing anything wrong.What did you expect to see?
That all nil checks return the correct result.
What did you see instead?
A nil check on a custom error type always returns true.
The text was updated successfully, but these errors were encountered: