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: structtag field repeats json warning with valid override #40102

Open
tylfin opened this issue Jul 7, 2020 · 1 comment
Open

cmd/vet: structtag field repeats json warning with valid override #40102

tylfin opened this issue Jul 7, 2020 · 1 comment

Comments

@tylfin
Copy link

@tylfin tylfin commented Jul 7, 2020

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

$ go version
go version go1.14.1 darwin/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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/[XX]/Library/Caches/go-build"
GOENV="/Users/[XX]/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/[XX]/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/w9/kv18_grs18x65fyzv1p5mvk00000gn/T/go-build893878327=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

When embedding two structs with duplicate JSON tags, e.g.:

type A struct {
   name string `json:"name"`
   ... // additional fields
}

type B struct {
   name string `json:"name"`
   ... // additional fields
}

type C struct {
    A
    B // raises go vet structtag warning
}

A structtag warning is raised by go vet. I think a reasonable workaround to the warning is to override the duplicate-tag on the top level, per extra rules here: https://golang.org/pkg/encoding/json/#Marshal, e.g.

type C struct {
   A
   B
   name string `json:"name"`
}

But go vet still raises the warning.

Note I did add the flag -structtag=false as a workaround but there are cases where I would like to be alerted, but only when no override has been set

What did you expect to see?

go vet treats top-level structtag overrides as a valid solution and no longer raises a warning.

What did you see instead?

go vet ignores the top-level override, resulting in structtag: struct field X repeats json tag "[X]" also at XXXX.go:XXX (govet)

@gopherbot gopherbot added the Tools label Jul 7, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 7, 2020
@tylfin tylfin changed the title x/tools/cmd/vet: structtag field repeats json warning with valid override cmd/vet: structtag field repeats json warning with valid override Jul 7, 2020
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 11, 2020

@dmitshur dmitshur modified the milestones: Unreleased, Backlog Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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