Skip to content

cmd/gofmt: -r 'bar(x) -> bar(x)' mistakenly replaces a comment with a newline in closures inside function #23275

@qfel

Description

@qfel

What version of Go are you using (go version)?

go version go1.9.2 linux/amd64

What did you do?

$ gofmt -r 'bar(x) -> bar(x)' /tmp/test.go

/tmp/test.go is:

package main

func main() {
    // Call foo().
    foo()
    bar(func() {
        // Call foo().
        foo()
    })
}

What did you expect to see?

Same contents

What did you see instead?

package main

func main() {
        // Call foo().
        foo()
        bar(func() {

                foo()
        })

}

Notice the comment in the closure passed to bar was replaced with an empty line, and an empty line was added after the call to bar.

The identity rewrite rule is for simplicity, this happens with more useful rewrites that act on bar too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions