]> Cypherpunks repositories - gostls13.git/commit
go/printer: indent lone comments in composite lits
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 29 Oct 2017 21:04:01 +0000 (21:04 +0000)
committerRobert Griesemer <gri@golang.org>
Wed, 15 Nov 2017 18:48:48 +0000 (18:48 +0000)
commita265f2e90eb928ab773ecabf48aefb11b188296d
treeb47019b7fb6023583bdaf51643eb8a9627a59289
parent89b7a08aea13d750f0bb48d88fea7dc867c9295c
go/printer: indent lone comments in composite lits

If a composite literal contains any comments on their own lines without
any elements, the printer would unindent the comments.

The comments in this edge case are written when the closing '}' is
written. Indent and outdent first so that the indentation is
interspersed before the comment is written.

Also note that the go/printer golden tests don't show the exact same
behaviour that gofmt does. Added a TODO to figure this out in a separate
CL.

While at it, ensure that the tree conforms to gofmt. The changes are
unrelated to this indentation fix, however.

Fixes #22355.

Change-Id: I5ac25ac6de95a236f1e123479127cc4dd71e93fe
Reviewed-on: https://go-review.googlesource.com/74232
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/printer/nodes.go
src/go/printer/testdata/comments.golden
src/go/printer/testdata/comments.input
src/math/big/int.go