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
tmp/sandbox205861443/main.go:18: non-name x.S on left side of :=
It appears that using the idiomatic map lookup pattern, there is a problem assigning the retrieved map value to a structure member (as opposed to a simple local variable). This occurs when a status variable (i.e. "ok") is used with the ":=" operator.
x.S, ok := m[2]
where: x is a local structure with member S, and ok is created within the statement due to the :=
See the playground link above.
The text was updated successfully, but these errors were encountered:
Brad,
Thanks for your timely response; however I am still confused about this.
This seems inconsistent. In one case I am assigning into a declared struct (x); in the other I am assigning to a declared scalar (s). Used in the context of v, ok := m[n] where v is either x.S or s, it looks like you're telling me I can only use a scalar variable for v? If this is truly how it is defined, obviously I'll abide by that. I just do not see why there's a distinction.
After looking at the language spec for a while, it still wasn't obvious to me that it was defined like this.
If there is a better forum to discuss this topic, I'd be glad to migrate. Let me know.
Thanks,
-Pete
@peteArnt
this problem is not related to map. It is a famous known design behaviour/issue/flaw (or whatever).
But now the implementation is really consistent with Go spec: the right of := must be pure identifiers, can't be object fields, array/slice/map elements or pointer dereferences.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version devel +73497c7 Thu Nov 10 01:34:03 2016 +0000 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN="/home/peter/mygo/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/peter/mygo"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build003323332=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/dIcyfHcos7
What did you expect to see?
A successful compilation
What did you see instead?
tmp/sandbox205861443/main.go:18: non-name x.S on left side of :=
It appears that using the idiomatic map lookup pattern, there is a problem assigning the retrieved map value to a structure member (as opposed to a simple local variable). This occurs when a status variable (i.e. "ok") is used with the ":=" operator.
x.S, ok := m[2]
where: x is a local structure with member S, and ok is created within the statement due to the :=
See the playground link above.
The text was updated successfully, but these errors were encountered: