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
After declare an error variable with type of error, and assign its value with a function that returned custom error (a struct with an interface of error). It will have issue when checking nil (err != nil) as the statement will always returnd true even the real value of the variable is nil. You can reproduce the bug using playground: https://go.dev/play/p/otd6w4e7nK1.
What did you expect to see?
The condition statement should return proper value when doing nil check. (if the value of variable err is nil, then err != nil should return false)
What did you see instead?
Even err (which declare as a type error, then later assign to a custom error) has value of nil but the condition err != nil is always returned true.
The text was updated successfully, but these errors were encountered:
Under the covers, interfaces are implemented as two elements, a type T and a value V.
...
An interface value is nil only if the V and T are both unset, (T=nil, V is not set), In particular, a nil interface will always hold a nil type. If we store a nil pointer of type *int inside an interface value, the inner type will be *int regardless of the value of the pointer: (T=*int, V=nil). Such an interface value will therefore be non-nil even when the pointer value V inside is nil.
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
After declare an error variable with type of
error
, and assign its value with a function that returned custom error (a struct with an interface oferror
). It will have issue when checking nil (err != nil
) as the statement will always returndtrue
even the real value of the variable isnil
. You can reproduce the bug using playground: https://go.dev/play/p/otd6w4e7nK1.What did you expect to see?
The condition statement should return proper value when doing nil check. (if the value of variable
err
isnil
, thenerr != nil
should returnfalse
)What did you see instead?
Even
err
(which declare as a typeerror
, then later assign to a custom error) has value ofnil
but the conditionerr != nil
is always returnedtrue
.The text was updated successfully, but these errors were encountered: