Skip to content

cmd/gofmt: trailing comments in composite literals are misaligned #76708

@mibk

Description

@mibk

Go version

go version go1.25.5 darwin/arm64

Description

I noticed that gofmt produces the following formatting for a byte slice literal:

fr.Write([]byte{
	0x00,       // Preamble
	0x00, 0xFF, // Start code
	dlen,      // LEN
	^dlen + 1, // LCS
	tfi,       // Type of Frame Identifier
})

My expectation was that comments would remain aligned consistently. Is this a known limitation or intended behavior of gofmt? Apologies if this was already reported.

(Go 1.24 produces the same output: https://go.dev/play/p/jxcnuqd6IsA?v=goprev)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.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