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

cmd/vet: warning with duplicate `json:"omitempty"` field tag #22595

Closed
ls42 opened this issue Nov 6, 2017 · 2 comments
Closed

cmd/vet: warning with duplicate `json:"omitempty"` field tag #22595

ls42 opened this issue Nov 6, 2017 · 2 comments

Comments

@ls42
Copy link

@ls42 ls42 commented Nov 6, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/stephan/workspace/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k7/b4_kf50n6p9cjdb_6r1sr91c0000gn/T/go-build245233983=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

Write the following code in VSCode:

// Host represents a computer, a VM or a similar system
type Host struct {
	Name          string `json:"hostname"`
	Domain        string `json:"domain"`
	Login         string `json:"login"`
	Contact       string `json:"contact"`
	CPUCores      uint   `json:"sp_number_processors"`
	CPUSpeed      string `json:"sp_current_processor_speed"`
	Memory        string `json:"memorysize_mb"`
	FacterVersion string `json:"facterversion"`
	Kernel        string `json:"kernelrelease"`
	Release       string `json:"operatingsystem"`
	Serial        string `json:"serialnumber"`
	IsVirtual     bool   `json:"is_virtual"`
	Disks         []Disk `json:"omitempty"`
	ChildVMs      []Host `json:"omitempty"`
}

Then save, which will trigger go tool vet on the file. The last line (ChildVMs...) will then be highlighted with a curly green line, indicating a warning, saying it has a duplicate tag that's already defined.

What did you expect to see?

No curly green line on the last field definition since it should be OK to have multiple lines with that tag.

Over at the repository for the Go-VSCode plugin I posted a screenshot.

@ALTree ALTree changed the title go tool vet gives warning with `json:"omitempty"` field tag cmd/vet: warning with duplicate `json:"omitempty"` field tag Nov 6, 2017
@ALTree

This comment has been minimized.

Copy link
Member

@ALTree ALTree commented Nov 6, 2017

You are missing the leading comma

json:",omitempty"

I believe it's required.

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Nov 6, 2017

@ALTree is correct. (As is cmd/vet... it found a real problem.)

@bradfitz bradfitz closed this Nov 6, 2017
@golang golang locked and limited conversation to collaborators Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.