Commit b5021f3f authored by Robert Griesemer's avatar Robert Griesemer

go/printer, gofmt: fix multi-line logic

A node spans multiple lines if the line difference
between start and end point is > 0 (rather than > 1).
Fixes some odd cases introduced by CL 5706055;
pointed out by dsymonds.

Added corresponding test case. The other change
in the .golden file reverts to the status before
the CL mentioned above and is correct.

gofmt -w src misc changes godoc.go back to where
it was before the CL mentioned above.

Fixes #3304.

R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5820044
parent 62bb39e2
......@@ -365,7 +365,7 @@ func (p *printer) setLineComment(text string) {
}
func (p *printer) isMultiLine(n ast.Node) bool {
return p.lineFor(n.End())-p.lineFor(n.Pos()) > 1
return p.lineFor(n.End())-p.lineFor(n.Pos()) > 0
}
func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool) {
......
......@@ -566,6 +566,17 @@ var (
a4, b4, c4 int // this line should be indented
)
// Test case from issue 3304: multi-line declarations must end
// a formatting section and not influence indentation of the
// next line.
var (
minRefreshTimeSec = flag.Int64("min_refresh_time_sec", 604800,
"minimum time window between two refreshes for a given user.")
x = flag.Int64("refresh_user_rollout_percent", 100,
"temporary flag to ramp up the refresh user rpc")
aVeryLongVariableName = stats.GetVarInt("refresh-user-count")
)
func _() {
var privateKey2 = &Block{Type: "RSA PRIVATE KEY",
Headers: map[string]string{},
......
......@@ -577,6 +577,16 @@ c3, d3 int // this line should be indented
a4, b4, c4 int // this line should be indented
)
// Test case from issue 3304: multi-line declarations must end
// a formatting section and not influence indentation of the
// next line.
var (
minRefreshTimeSec = flag.Int64("min_refresh_time_sec", 604800,
"minimum time window between two refreshes for a given user.")
x = flag.Int64("refresh_user_rollout_percent", 100,
"temporary flag to ramp up the refresh user rpc")
aVeryLongVariableName = stats.GetVarInt("refresh-user-count")
)
func _() {
var privateKey2 = &Block{Type: "RSA PRIVATE KEY",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment