Commit 2f816d5b authored by Robert Griesemer's avatar Robert Griesemer

Don't print ()'s around a range clause's expression.

Fixes #605.

R=rsc
CC=golang-dev
https://golang.org/cl/207108
parent e7fc5c27
...@@ -671,6 +671,7 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi ...@@ -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) { ...@@ -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
......
...@@ -144,6 +144,9 @@ func _() { ...@@ -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
} }
......
...@@ -107,6 +107,7 @@ func _() { ...@@ -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
} }
......
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