Skip to content

reflect:documentation for IsValid and IsZero is confusing #34152

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

Closed
mohit10verma opened this issue Sep 6, 2019 · 2 comments
Closed

reflect:documentation for IsValid and IsZero is confusing #34152

mohit10verma opened this issue Sep 6, 2019 · 2 comments
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mohit10verma
Copy link
Contributor

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

$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/administrator/.cache/go-build"
GOENV="/home/administrator/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/administrator/Work/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/administrator/Work/go/src/go-latest"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/administrator/Work/go/src/go-latest/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build484657166=/tmp/go-build -gno-record-gcc-switches"

What did you do?

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

What did you expect to see?

For a zero value,
value.IsZero() = true , and
value.IsValid() = false
according to the documentation here: https://golang.org/pkg/reflect/#Value.IsValid

What did you see instead?

value.IsZero() = true
value.IsValid() = true

@mohit10verma mohit10verma changed the title value.IsValid() should return false if value.IsZero() is true reflect.Value.IsValid() should return false if reflect.Value.IsZero() is true Sep 6, 2019
@dsnet
Copy link
Member

dsnet commented Sep 6, 2019

This is working as intended, but slightly confusing in the documentation.

The documentation for reflect.Value.IsValid says "It returns false if v is the zero Value". Note the uppercase Value, it's referring to the reflect.Value, an abstract representation of any Go value.

The documentation for reflect.Value.IsZero says "IsZero reports whether v is the zero value for its type". Note the lowercase value, it's referring the underlying Go value that the reflect.Value is representing.

@dsnet dsnet changed the title reflect.Value.IsValid() should return false if reflect.Value.IsZero() is true reflect:documentation for IsValid and IsZero is confusing Sep 6, 2019
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Sep 6, 2019
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/193841 mentions this issue: reflect: enhance docs for IsZero and IsValid

mkungla added a commit to mkungla/go that referenced this issue Sep 6, 2019
Make it clear that IsValid checks that we have valid
reflect.Value and not the value of `v`

fixes golang#34152

Change-Id: Ib3d359eeb3a82bf733b9ed17c777fc4c143bc29c
mkungla added a commit to mkungla/go that referenced this issue Sep 7, 2019
Make it clear that IsValid checks that we have valid
reflect.Value and not the value of `v`

fixes golang#34152

Change-Id: Ib3d359eeb3a82bf733b9ed17c777fc4c143bc29c
mkungla added a commit to mkungla/go that referenced this issue Sep 7, 2019
Make it clear that IsValid checks that we have valid
reflect.Value and not the value of `v`

fixes golang#34152

Change-Id: Ib3d359eeb3a82bf733b9ed17c777fc4c143bc29c
@FiloSottile FiloSottile added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 10, 2019
@FiloSottile FiloSottile added this to the Go1.14 milestone Sep 10, 2019
@golang golang locked and limited conversation to collaborators Sep 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants