Skip to content

cmd/gofmt: -r strips some comments in array types #57680

@rillig

Description

@rillig

What did you do?

package main

type CommentInBrackets [/*c*/]  int
type CommentAfterBrackets [] /*c*/ int

Running gofmt -r 'any -> any' moves the first comment out of the brackets, which may be surprising to a user but understandable once you know that ast.ArrayType only records the position of Lbrack but not of Rbrack.

Running gofmt -r 'a -> a' removes both comments, which surprised me. I expected that ast.CommentMap would record all necessary data to preserve at least the second comment.

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions