Skip to content

cmd/gofmt: Comments are incorrectly moved across commas #68190

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

Closed
varungandhi-src opened this issue Jun 26, 2024 · 2 comments
Closed

cmd/gofmt: Comments are incorrectly moved across commas #68190

varungandhi-src opened this issue Jun 26, 2024 · 2 comments

Comments

@varungandhi-src
Copy link

Go version

HEAD

Output of go env in your module/workspace:

n/a - Tested on https://go.dev/play/

What did you do?

Write some code like:

foo(x, /* name */ y)

Then run go fmt

What did you see happen?

The code gets re-formatted to:

foo(x /* name */, y)
CleanShot.2024-06-26.at.18.12.00.mp4

This changes the meaning of the comment, as it seems to apply to the preceding argument.

This problem also applies to commas in slice literals and comments. I have not checked the behavior with other grammar constructs that have commas.

What did you expect to see?

The comment should respect the position relative to the comma. Otherwise, one has to introduce an unnecessary line break to force the comment from not being moved to the wrong place.

@varungandhi-src
Copy link
Author

Closing as duplicate of #13113

@varungandhi-src varungandhi-src closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants