Skip to content

cmd/gofmt: odd comment alignment #9064

Closed
@cznic

Description

@cznic
What does 'go version' print?
go version 1.3.2 // According to fmt.Println(runtime.Version()) in playground.

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1.
Open http://play.golang.org/p/E22kYjkJpS

2.
Click button "Format"

What happened?
Comment at line 4 jumps to the right.

What should have happened instead?
Comment at line 4 should have probably stay where it was.

Please provide any additional information below.
My hypothesis is that gofmt wrongly computes the length of line 5 using also len() of
the string literal as if it was a quoted string; in an attempt to align the comments at
L4 and L7 as if they are adjacent. But the raw string literal has newlines embedded so
they are not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions