mirror of
https://github.com/golang/go
synced 2024-11-21 20:34:40 -07:00
Don't print ()'s around a range clause's expression.
Fixes #605. R=rsc CC=golang-dev https://golang.org/cl/207108
This commit is contained in:
parent
e7fc5c2789
commit
2f816d5b73
@ -671,6 +671,7 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi
|
||||
// no parenthesis needed
|
||||
p.print(x.Op)
|
||||
if x.Op == token.RANGE {
|
||||
// TODO(gri) Remove this code if it cannot be reached.
|
||||
p.print(blank)
|
||||
}
|
||||
p.expr1(x.X, prec, depth, 0, multiLine)
|
||||
@ -1075,7 +1076,7 @@ func (p *printer) stmt(stmt ast.Stmt, multiLine *bool) {
|
||||
p.expr(s.Value, multiLine)
|
||||
}
|
||||
p.print(blank, s.TokPos, s.Tok, blank, token.RANGE, blank)
|
||||
p.expr(s.X, multiLine)
|
||||
p.expr(stripParens(s.X), multiLine)
|
||||
p.print(blank)
|
||||
p.block(s.Body, 1, true)
|
||||
*multiLine = true
|
||||
|
@ -144,6 +144,9 @@ func _() {
|
||||
for x := range []int{} {
|
||||
use(x)
|
||||
}
|
||||
for x := range []int{} {
|
||||
use(x)
|
||||
} // no parens printed
|
||||
}
|
||||
|
||||
|
||||
|
1
src/pkg/go/printer/testdata/statements.input
vendored
1
src/pkg/go/printer/testdata/statements.input
vendored
@ -107,6 +107,7 @@ func _() {
|
||||
}
|
||||
for x := expr;expr;expr = false { use(x) }
|
||||
for x := range []int{} { use(x) }
|
||||
for x := range (([]int{})) { use(x) } // no parens printed
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user