]> Cypherpunks repositories - gostls13.git/commit
go/format: fix //line corner case when formatting statements
authorDidier Spezia <didier.06@gmail.com>
Sat, 20 Jun 2015 11:25:59 +0000 (11:25 +0000)
committerRobert Griesemer <gri@golang.org>
Wed, 24 Jun 2015 21:45:49 +0000 (21:45 +0000)
commitc68f2f89963cfc9d10b43d33603b6fa588d56f9d
tree966eb7bcab12ca65b63c515ed9c115a34fd159dd
parent77082481d48c8cd8ea93328f9ab962092fe0183f
go/format: fix //line corner case when formatting statements

The code formatting mechanism can be applied to partial Go code,
such as a list of statements. The statements are wrapped into a
function definition (to be parsed fine), and unwrapped after formatting.

When the statements contain //line annotations, it may fail,
because not all comments are flushed by the printer before the final '}'.
Formatting "\ta()\n//line :1" results in "\ta() }\n\n//line", which
is wrong.

Tweaked the wrapping/unwrapping code to make sure comments are flushed
before the '}'.

Fixes #11276

Change-Id: Id15c80279b0382ee9ed939cca1647f525c4929f5
Reviewed-on: https://go-review.googlesource.com/11282
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/format/format_test.go
src/internal/format/format.go