Skip to content

cmd/gofmt: moves comment in for #9460

@sethwklein

Description

@sethwklein

On playground (and elsewhere), this code

package main

func main() {
        for i := 0; i < 1 /* 9000 */ ; i++ {
                _ = i
        }
}

is transformed by gofmt into this code:

package main

func main() {
    for i := 0; i < 1; /* 9000 */ i++ {
        _ = i
    }
}

It has swapped the comment and the nearby semi-colon.

This code arises when temporarily changing the limit of a loop.

I think this swap changes the context of the comment, possibly changing its meaning.

It also means that I'll have to swap 9000 (in this example) and the semi-colon back when restoring the original loop limit.

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