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: don't report duplicate json tags when field shadowing is used #30846

Open
flimzy opened this Issue Mar 14, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@flimzy
Copy link

flimzy commented Mar 14, 2019

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

$ go version
go version go1.12 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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jonhall/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jonhall/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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-build643199218=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Given this simple code:

package test

type Foo struct {
	Foo string `json:"foo"`
	Bar string `json:"bar"`
}

type Bar struct {
	Foo
	Bar int `json:"bar"`
}

As of Go 1.12, go vet complains:

./test.go:10:2: struct field Bar repeats json tag "bar" also at test.go:5

What did you expect to see?

I expect to see no complaint from go vet, as I did in Go 1.11 and earlier, since the field defined at line 5 is hidden, so is disregarded by the json package.

@mvdan

This comment has been minimized.

Copy link
Member

mvdan commented Mar 18, 2019

This is #30465; the enhancement to the vet check was temporarily reverted in 1.12.1. I plan to simply fix the check for 1.13 in master, as opposed to disabling it.

I wanted to file a separate issue to track that, but you beat me to it :) I'll use this one, if that's okay.

@mvdan mvdan changed the title cmd/vet: Improperly reports duplicate json tag for hidden fields cmd/vet: don't report duplicate json tags when field shadowing is used Mar 18, 2019

@mvdan mvdan added this to the Go1.13 milestone Mar 18, 2019

@mvdan mvdan added the NeedsFix label Mar 18, 2019

@mvdan mvdan self-assigned this Mar 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.