Skip to content

go/printer: wonky alignment when mixing embedded and typed fields along with struct tags in a struct definition #7199

@gopherbot

Description

@gopherbot

by cudmore.mb:

*What steps will reproduce the problem?*
1. Format http://play.golang.org/p/jzmwwldMwt
2. Format 

*What is the expected output?*
{{{
type Field struct {
    ID       `json:"UID"` // comment
    Label ID `json:"Lbl"` // comment
    *N                    // comment

    Value string `json:"Val"`
    Inheritable  `json:"Inh"` // comment

    a int // comment
    b string
    c int // comment
}
}}}

*What do you see instead?*
{{{
type Field struct {
    ID    `json:"UID"` // comment
    Label ID           `json:"Lbl"` // comment
    *N                 // comment

    Value       string       `json:"Val"`
    Inheritable `json:"Inh"` // comment

    a int // comment
    b string
    c int // comment
}
}}}

*Which version are you using?*
go1.2

I opened a discussion on this here:
https://groups.google.com/d/topic/golang-nuts/5RlC11J7XNE/discussion

It would be great if go fmt would align the parts of field definitions by kind (type,
tag, comment), rather than by index (first parts align, second parts), across contiguous
field definitions until an intermittent newline or comment.

The type of anonymous fields would be regarded as the field name, and would not
contribute to computing the alignment of the types. All types in a contiguous list of
fields would align to the rightmost, and then all tags, and then all comments.

However, this does get tricky: http://play.golang.org/p/Z_OPEbej-v

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions