Skip to content

go/ast,go/format: newline missing between modified comment and function #66439

Description

@ldemailly

Go version

go version go1.21.8 darwin/arm64

but same with 1.22 and Go dev branch on playground

What did you do?

Mutating node.Comments.List.Text produces incorrect formatting if adding newlines to /* */ style comments:

https://go.dev/play/p/IoJy719eLRt

As part of breaking too long lines, I stepped on the issue that if I cut a multi line comment that is before a function, once output back a new line between the comment and the function is missing eg

/*
 * multi
 * line comment.
 */func main() {
}

is produced

What did you see happen?

/*
 * multi
 * line comment.
 */func main() {

What did you expect to see?

/*
 * multi
 * line comment.
*/
func main() {

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions