Skip to content

cmd/gofmt: faulty comment re-arrangement in argument lists #13113

@matttproud

Description

@matttproud

Hi,

I noticed today that gofmt (on the Playground at least) reformats /* */ comments that are inlined in argument lists inconsistently and in a non-faithful manner to their original ordering in the list:

Pre-Gofmt

fmt.Println(/* before first */ "first", /* before second */ "second")
demo

Post-Gofmt

fmt.Println( /* before first */ "first" /* before second */, "second")
demo

Notice how in the Post-Gofmt case it moves the comment that occurred after the comma to before.

This behavior is incongruent to what happens when the argument lists are spread across multiple lines:

Newline Distributed Pre-Gofmt

package main

import "fmt"

func main() {
    fmt.Println(
    /* before first */ "first")
    fmt.Println(
    /* before first */ "first",
    /* before second */ "second")   
}

demo

Newline Distributed Post-Gofmt

package main

import "fmt"

func main() {
    fmt.Println(
        /* before first */ "first")
    fmt.Println(
        /* before first */ "first",
        /* before second */ "second")
}

demo

For the pre cases, be sure to click Format in the Go Playground demo to see the post-state.

Metadata

Metadata

Assignees

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