]> Cypherpunks repositories - gostls13.git/commit
go/printer: set prefix correctly when all comment lines blank
authorDmitri Shuralyov <shurcooL@gmail.com>
Mon, 2 Feb 2015 09:28:10 +0000 (01:28 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 2 Feb 2015 18:41:05 +0000 (18:41 +0000)
commit928c83ff2cd13e5973827b2abde43b6dc901ec85
treedcdbae6baf4e0fe2cc45355c6f7e500179329848
parent187cccbde167f6979fb026524eea1004ec1d625a
go/printer: set prefix correctly when all comment lines blank

In stripCommonPrefix, the prefix was correctly calculated in all cases,
except one. That unhandled case is when there are more than 2 lines,
but all lines are blank (other than the first and last lines,
which contain /* and */ respectively).
This change detects that case and correctly sets the prefix calculated
from the last line. This is consistent with the (correct) behavior
that happens when there's at least one non-blank line.
That fixes issue #9751 that occurs for problematic input,
where cmd/gofmt and go/source would insert extra indentation on
every format operation. It also allows go/printer itself to print
such parsed files in an expected way.

Fixes #9751.

Change-Id: Id3dfb945beb59ffad3705085a3c285fca30a5f87
Reviewed-on: https://go-review.googlesource.com/3684
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/printer/printer.go
src/go/printer/testdata/comments.golden
src/go/printer/testdata/comments.input