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/gofmt: -r strips some comments in array types #57680

Open
rillig opened this issue Jan 8, 2023 · 1 comment
Open

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

rillig opened this issue Jan 8, 2023 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rillig
Copy link
Contributor

rillig commented Jan 8, 2023

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.

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 9, 2023
@cagedmantis cagedmantis modified the milestones: Backlog, Unreleased Jan 9, 2023
@cagedmantis
Copy link
Contributor

/cc @griesemer @mvdan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants