Skip to content

cmd/vet: Doesn't complain when the field tags are not parsable by the reflect: StructTag.Get() call #14466

Closed
@szank

Description

@szank

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions