Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interface{} == nil comparison returns false instead of true #28241

Closed
ston1th opened this issue Oct 16, 2018 · 2 comments
Closed

interface{} == nil comparison returns false instead of true #28241

ston1th opened this issue Oct 16, 2018 · 2 comments

Comments

@ston1th
Copy link

ston1th commented Oct 16, 2018

What version of Go are you using (go version)?

go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

https://play.golang.org/p/bwmjw0Rt_wk

What did you expect to see?

n2 == nil should be true (reflect.ValueOf(n2).IsNil() reports true correctly)

What did you see instead?

n2 == nil is false

@deanveloper
Copy link

deanveloper commented Oct 16, 2018

Intended behavior. An interface consists of two "fields", a type, and a pointer to the value.

In order for an interface to == nil, both the type and value need to be nil.

https://golang.org/doc/faq#nil_error

@ston1th
Copy link
Author

ston1th commented Oct 16, 2018

Ahh, thanks for clearing things up.

@ston1th ston1th closed this as completed Oct 16, 2018
@golang golang locked and limited conversation to collaborators Oct 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants