mirror of
https://github.com/golang/go
synced 2024-11-21 14:44:40 -07:00
go/printer, gofmt: print "select {}" on one line
No impact on existing sources under src, misc. Fixes #1959. R=r, rsc, r CC=golang-dev https://golang.org/cl/4589056
This commit is contained in:
parent
5d9dbe19a7
commit
333167ff35
@ -1158,8 +1158,14 @@ func (p *printer) stmt(stmt ast.Stmt, nextIsRBrace bool, multiLine *bool) {
|
||||
|
||||
case *ast.SelectStmt:
|
||||
p.print(token.SELECT, blank)
|
||||
p.block(s.Body, 0)
|
||||
*multiLine = true
|
||||
body := s.Body
|
||||
if len(body.List) == 0 && !p.commentBefore(p.fset.Position(body.Rbrace)) {
|
||||
// print empty select statement w/o comments on one line
|
||||
p.print(body.Lbrace, token.LBRACE, body.Rbrace, token.RBRACE)
|
||||
} else {
|
||||
p.block(body, 0)
|
||||
*multiLine = true
|
||||
}
|
||||
|
||||
case *ast.ForStmt:
|
||||
p.print(token.FOR)
|
||||
|
15
src/pkg/go/printer/testdata/statements.golden
vendored
15
src/pkg/go/printer/testdata/statements.golden
vendored
@ -111,6 +111,21 @@ func _() {
|
||||
}
|
||||
|
||||
|
||||
// Formatting of selected select statements.
|
||||
func _() {
|
||||
select {}
|
||||
select { /* this comment should not be tab-aligned because the closing } is on the same line */
|
||||
}
|
||||
select { /* this comment should be tab-aligned */
|
||||
}
|
||||
select { // this comment should be tab-aligned
|
||||
}
|
||||
select {
|
||||
case <-c:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Formatting of for-statement headers.
|
||||
func _() {
|
||||
for {
|
||||
|
13
src/pkg/go/printer/testdata/statements.input
vendored
13
src/pkg/go/printer/testdata/statements.input
vendored
@ -91,6 +91,19 @@ func _() {
|
||||
}
|
||||
|
||||
|
||||
// Formatting of selected select statements.
|
||||
func _() {
|
||||
select {
|
||||
}
|
||||
select { /* this comment should not be tab-aligned because the closing } is on the same line */ }
|
||||
select { /* this comment should be tab-aligned */
|
||||
}
|
||||
select { // this comment should be tab-aligned
|
||||
}
|
||||
select { case <-c: }
|
||||
}
|
||||
|
||||
|
||||
// Formatting of for-statement headers.
|
||||
func _() {
|
||||
for{}
|
||||
|
Loading…
Reference in New Issue
Block a user