1
0
mirror of https://github.com/golang/go synced 2024-11-22 08:54:39 -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:
Robert Griesemer 2010-02-16 10:19:51 -08:00
parent e7fc5c2789
commit 2f816d5b73
3 changed files with 6 additions and 1 deletions

View File

@ -671,6 +671,7 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi
// no parenthesis needed // no parenthesis needed
p.print(x.Op) p.print(x.Op)
if x.Op == token.RANGE { if x.Op == token.RANGE {
// TODO(gri) Remove this code if it cannot be reached.
p.print(blank) p.print(blank)
} }
p.expr1(x.X, prec, depth, 0, multiLine) 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.expr(s.Value, multiLine)
} }
p.print(blank, s.TokPos, s.Tok, blank, token.RANGE, blank) 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.print(blank)
p.block(s.Body, 1, true) p.block(s.Body, 1, true)
*multiLine = true *multiLine = true

View File

@ -144,6 +144,9 @@ func _() {
for x := range []int{} { for x := range []int{} {
use(x) use(x)
} }
for x := range []int{} {
use(x)
} // no parens printed
} }

View File

@ -107,6 +107,7 @@ func _() {
} }
for x := expr;expr;expr = false { use(x) } for x := expr;expr;expr = false { use(x) }
for x := range []int{} { use(x) } for x := range []int{} { use(x) }
for x := range (([]int{})) { use(x) } // no parens printed
} }