Skip to content

Syntax issue with Go compiler when using two-value assignment from map to struct member #17871

Closed
@peteArnt

Description

@peteArnt

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions