Skip to content

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

Closed as not planned
@varungandhi-src

Description

@varungandhi-src

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions