diff options
author | Robert Griesemer <gri@golang.org> | 2014-09-12 11:18:12 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2014-09-12 11:18:12 -0700 |
commit | a7e2b08915f3f88a97bc4dfa0d2d66e2eb6993a7 (patch) | |
tree | 875a88a615949f9055e1f3237d2cbe3bbbb77341 /src | |
parent | e9186a4e1e3a6db761a5e81a6426ca04db006e52 (diff) | |
download | go-a7e2b08915f3f88a97bc4dfa0d2d66e2eb6993a7.tar.gz |
go/printer: don't reduce nesting depth twice if parentheses are present around an expr
No impact on formatting on our repos.
Fixes issue 8021.
LGTM=adonovan
R=adonovan, dvyukov
CC=golang-codereviews
https://codereview.appspot.com/142020043
Diffstat (limited to 'src')
-rw-r--r-- | src/go/printer/nodes.go | 2 | ||||
-rw-r--r-- | src/go/printer/testdata/expressions.golden | 5 | ||||
-rw-r--r-- | src/go/printer/testdata/expressions.input | 5 | ||||
-rw-r--r-- | src/go/printer/testdata/expressions.raw | 5 | ||||
-rw-r--r-- | src/go/printer/testdata/statements.golden | 2 |
5 files changed, 17 insertions, 2 deletions
diff --git a/src/go/printer/nodes.go b/src/go/printer/nodes.go index e52236ddc..d5a69349b 100644 --- a/src/go/printer/nodes.go +++ b/src/go/printer/nodes.go @@ -736,7 +736,7 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) { if _, hasParens := x.X.(*ast.ParenExpr); hasParens { // don't print parentheses around an already parenthesized expression // TODO(gri) consider making this more general and incorporate precedence levels - p.expr0(x.X, reduceDepth(depth)) // parentheses undo one level of depth + p.expr0(x.X, depth) } else { p.print(token.LPAREN) p.expr0(x.X, reduceDepth(depth)) // parentheses undo one level of depth diff --git a/src/go/printer/testdata/expressions.golden b/src/go/printer/testdata/expressions.golden index fbe8275b3..e3d17a465 100644 --- a/src/go/printer/testdata/expressions.golden +++ b/src/go/printer/testdata/expressions.golden @@ -94,6 +94,11 @@ func _() { _ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666) _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx) + // test case for issue 8021 + // want: + // ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + _ = ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + // the parser does not restrict expressions that may appear as statements true 42 diff --git a/src/go/printer/testdata/expressions.input b/src/go/printer/testdata/expressions.input index f4d20fa0f..d20a59350 100644 --- a/src/go/printer/testdata/expressions.input +++ b/src/go/printer/testdata/expressions.input @@ -95,6 +95,11 @@ func _() { _ = Open(dpath + "/file", O_WRONLY | O_CREAT, 0666) _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx) + // test case for issue 8021 + // want: + // ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + _ = ([]bool{})[([]int{})[((1) + (((((1) + (((((((1) * (((((1) + (1))) + (1))))) + (1))) * (1))))) + (1))))]] + // the parser does not restrict expressions that may appear as statements true 42 diff --git a/src/go/printer/testdata/expressions.raw b/src/go/printer/testdata/expressions.raw index 97bc81dad..235733695 100644 --- a/src/go/printer/testdata/expressions.raw +++ b/src/go/printer/testdata/expressions.raw @@ -94,6 +94,11 @@ func _() { _ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666) _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx) + // test case for issue 8021 + // want: + // ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + _ = ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + // the parser does not restrict expressions that may appear as statements true 42 diff --git a/src/go/printer/testdata/statements.golden b/src/go/printer/testdata/statements.golden index 324b6cdd0..4b1346047 100644 --- a/src/go/printer/testdata/statements.golden +++ b/src/go/printer/testdata/statements.golden @@ -444,7 +444,7 @@ func _() { } if x == a+b*(T{42}[0]) { } - if x == a+(b * (T{42}[0])) { + if x == a+(b*(T{42}[0])) { } if x == a+b*(T{42}[0]) { } |