Description
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="/home/24G/.bin"
GOCACHE="/home/24G/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/24G/go"
GOPROXY=""
GORACE=""
GOROOT="/snap/go/2890"
GOTMPDIR=""
GOTOOLDIR="/snap/go/2890/pkg/tool/linux_amd64"
GCCGO="gccgo"
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-build434234612=/tmp/go-build -gno-record-gcc-switches"
What did you do?
https://play.golang.org/p/uU1XNXaFYG-
What did you expect to see?
This isn't a bug report, that's exactly what I expected haha. But the purpose of this issue is to get a more helpful error message.
What did you see instead?
cannot take the address of 5
This is quite repulsive toward beginners. People who encounter this error may not understand exactly how constant values work, and what the differences between constants and normal values (after all, they look a lot like variables). Pointers are extremely hard for beginners to deal with, and changing this error message will make the language a bit more approachable.
This is especially unintuitive because &StructValue{...}
is okay, but &5
is not.
I propose instead that the message is changed to cannot take the address of the constant value <const>
. This should at least explain a reason why the value is not addressable.
If there are cases where this is error message change would be unhelpful, that would be important to consider.