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

Unnecessary syntax error when creating a key-value pairs using map #40394

Closed
BLasan opened this issue Jul 24, 2020 · 3 comments
Closed

Unnecessary syntax error when creating a key-value pairs using map #40394

BLasan opened this issue Jul 24, 2020 · 3 comments

Comments

@BLasan
Copy link

BLasan commented Jul 24, 2020

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

$ go version
go version go1.14.6 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/benura/.cache/go-build"
GOENV="/home/benura/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/benura/golib:/home/benura/Desktop/goInitProj"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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-build490309697=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Used map create some key value pairs. Final key value pair will require a ',' to be finished. Otherwise a syntax error will be prompting on the console. (VS-Code 1.46) This is a bit conflict with other programming languages like javascript when defining key-value pairs. Is it really necessary to add a comma after the last key-value pair with in the map.
structMap := map[string]string{ "name": "John", "age": "24", "location": "Colombo" }

What did you expect to see?

No syntax error.

What did you see instead?

Screenshot from 2020-07-24 23-41-43
'}' should be right after the "Colombo" value in order to prevent from having this syntax error.

@icholy
Copy link

icholy commented Jul 24, 2020

Your example compiles fine https://play.golang.org/p/E_BInnwuKc6

@BLasan
Copy link
Author

BLasan commented Jul 24, 2020

Your example compiles fine https://play.golang.org/p/E_BInnwuKc6

Actually what I meant was this ,
Screenshot from 2020-07-25 00-03-00

When we end the curly braces like in the attached image, it will pop out a syntax error.

@ianlancetaylor
Copy link
Contributor

When showing code, please use plain text or a playground link, not an image. Especially not a white-on-black image. Images are hard to read, and they don't support cut-and-paste of text. Code is plain text, so show it as plain text.

In this case the problem appears to be a missing comma at the end of the "location" line, just as the error message says.

Closing because this seems to be expected behavior.

@golang golang locked and limited conversation to collaborators Jul 24, 2021
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

4 participants