Skip to content

cmd/gofmt: non-idempotent formatting of line comments #13702

@cezarsa

Description

@cezarsa

tl;dr: Access http://play.golang.org/p/Ry5OUCK43C; Click Format; Click Format.

After running the following snippet through gofmt -w:

package main

//line x:1


func main() {
}

The output is:

package main

//line x:1

func main() {
}

This output looks correct with a single newline between //line and func main. However if we run gofmt -w again on the same file the output is different:

package main

//line x:1
func main() {
}

Now the newline between //line and func main was removed. This behavior is different from what would happen if instead of //line we had a regular commented line.

This was tested both on master and 1.5.1:

$ go version
go version devel +97f854c Sat Dec 19 10:00:04 2015 +0000 darwin/amd64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions