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: Doesn't complain when the field tags are not parsable by the reflect: StructTag.Get() call #14466

szank opened this issue Feb 22, 2016 · 3 comments


Copy link

@szank szank commented Feb 22, 2016

Hi, I have noticed a problem with go vet that have stung me recently.
Go vet doesn't report an error in the field tag formatting.

Let's take an example struct :

// TestStruct comment
type TestStruct struct {
    A string `json:"jsona",xml:"xmla"`

As you can see I have set the field tags, and while the tags looks OK, the tag format is incorrect. To illustrate, the example code:

package main

import (

// TestStruct comment
type TestStruct struct {
    A string `json:"jsona",xml:"xmla"`

func main() {

    var theStruct = TestStruct{"A"}

    fmt.Println("First field tag: ", reflect.TypeOf(theStruct).Field(0).Tag)
    fmt.Println("Json tag value:  ", reflect.TypeOf(theStruct).Field(0).Tag.Get("json"))
    fmt.Println("XML tag value:   ", reflect.TypeOf(theStruct).Field(0).Tag.Get("xml"))

Did return

First field tag:  json:"jsona",xml:"xmla"
Json tag value:   jsona
XML tag value:  

The problem here is the coma character between json and xml tags.
The go vet tool doesn't complain about this type of error and I would like to fix it if it is OK.

I will raise a pull request if the maintainers agree that this is a bug in the go vet tool indeed.

Copy link

@minux minux commented Feb 22, 2016

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Feb 22, 2016
@rsc rsc modified the milestones: Go1.8, Go1.7 May 18, 2016
@quentinmit quentinmit added the NeedsFix label Oct 6, 2016
Copy link

@rsc rsc commented Oct 25, 2016

Actually the tags are parseable in this case. The tag json:"jsona",xml:"xmla" is the same as json:"jsona" ,xml:"xmla". That is, there is an entry with key json and an entry with key ,xml. If you did tag.Get(",xml") you could retrieve the second one.

That said, it's obviously a mistake and probably one vet should catch even though it's not technically illegal. Will send a CL.

Copy link

@gopherbot gopherbot commented Oct 25, 2016

CL mentions this issue.

@gopherbot gopherbot closed this in e3324a4 Oct 26, 2016
@golang golang locked and limited conversation to collaborators Oct 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants