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

Closed
szank opened this issue Feb 22, 2016 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@szank
Copy link

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 (
    "fmt"
    "reflect"
)

// 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.

@minux
Copy link
Member

minux commented Feb 22, 2016 via email

@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 The path to resolution is known, but the work has not been done. label Oct 6, 2016
@rsc
Copy link
Contributor

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.

@gopherbot
Copy link

CL https://golang.org/cl/32031 mentions this issue.

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants