]> Cypherpunks repositories - gostls13.git/commitdiff
go/printer: don't reduce nesting depth twice if parentheses are present around an...
authorRobert Griesemer <gri@golang.org>
Fri, 12 Sep 2014 18:18:12 +0000 (11:18 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 12 Sep 2014 18:18:12 +0000 (11:18 -0700)
No impact on formatting on our repos.

Fixes #8021.

LGTM=adonovan
R=adonovan, dvyukov
CC=golang-codereviews
https://golang.org/cl/142020043

src/go/printer/nodes.go
src/go/printer/testdata/expressions.golden
src/go/printer/testdata/expressions.input
src/go/printer/testdata/expressions.raw
src/go/printer/testdata/statements.golden

index e52236ddc6425a098d3ed5f525df234180e9b673..d5a69349beba8bdcf72ea914e8ed2a74a84ad983 100644 (file)
@@ -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
index fbe8275b3a577a589f747d3759cc4b8f79084551..e3d17a4653f4bc20f567ba78d022512ab197dbb4 100644 (file)
@@ -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
index f4d20fa0f77466cd02c19c4a583bac9d02378b8c..d20a59350ed6db32f125ef9df9d93eeb6d28993d 100644 (file)
@@ -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
index 97bc81dad87e916be2c4e2e1b2b3ebf5ccbeeab8..2357336957fe0c04905acdc1285d02b1dc192fbd 100644 (file)
@@ -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
index 324b6cdd0f4dbcc94c2efc16a462f4a2e012e9ee..4b13460473553fb269a568595296d457104427f7 100644 (file)
@@ -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]) {
        }