]> Cypherpunks repositories - gostls13.git/commitdiff
go/printer: fix printing of variadic function calls
authorAnthony Martin <ality@pbrane.org>
Mon, 27 Feb 2012 21:56:43 +0000 (13:56 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 27 Feb 2012 21:56:43 +0000 (13:56 -0800)
Fixes #3130.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5697062

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

index cd5e075c16c9a0d84fc39fa19dd2843b29fbacc7..2205f633f1d502b0d0f774fde7f5557f35bb95f5 100644 (file)
@@ -804,9 +804,14 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, multiLine *bool) {
                }
                p.expr1(x.Fun, token.HighestPrec, depth, multiLine)
                p.print(x.Lparen, token.LPAREN)
-               p.exprList(x.Lparen, x.Args, depth, commaSep|commaTerm, multiLine, x.Rparen)
                if x.Ellipsis.IsValid() {
+                       p.exprList(x.Lparen, x.Args, depth, commaSep, multiLine, x.Ellipsis)
                        p.print(x.Ellipsis, token.ELLIPSIS)
+                       if x.Rparen.IsValid() && p.lineFor(x.Ellipsis) < p.lineFor(x.Rparen) {
+                               p.print(token.COMMA, formfeed)
+                       }
+               } else {
+                       p.exprList(x.Lparen, x.Args, depth, commaSep|commaTerm, multiLine, x.Rparen)
                }
                p.print(x.Rparen, token.RPAREN)
 
index 95fdd95ffbba598e94b986fda2684286ba42eeb6..45fa4d97a4a5ca89ba58cae0cc796ba0f6d4662a 100644 (file)
@@ -625,3 +625,25 @@ func f() {
                log.Fatal(err)
        }
 }
+
+// Handle multi-line argument lists ending in ... correctly.
+// Was issue 3130.
+func _() {
+       _ = append(s, a...)
+       _ = append(
+               s, a...)
+       _ = append(s,
+               a...)
+       _ = append(
+               s,
+               a...)
+       _ = append(s, a...,
+       )
+       _ = append(s,
+               a...,
+       )
+       _ = append(
+               s,
+               a...,
+       )
+}
index d113149835212858ca280826e6acbf6a412e6c71..f545c66057ca93d00cc8b6b07f2476f62056017e 100644 (file)
@@ -654,3 +654,25 @@ func f() {
            log.Fatal(err)
        }
 }
+
+// Handle multi-line argument lists ending in ... correctly.
+// Was issue 3130.
+func _() {
+       _ = append(s, a...)
+       _ = append(
+               s, a...)
+       _ = append(s,
+               a...)
+       _ = append(
+               s,
+               a...)
+       _ = append(s, a...,
+       )
+       _ = append(s,
+               a...,
+       )
+       _ = append(
+               s,
+               a...,
+       )
+}
index 3442ba9b9501da9e83b2c900ce03def1bfecbe74..87a4b00836d168d3169734ca0ba5415e082bffcb 100644 (file)
@@ -625,3 +625,25 @@ func f() {
                log.Fatal(err)
        }
 }
+
+// Handle multi-line argument lists ending in ... correctly.
+// Was issue 3130.
+func _() {
+       _ = append(s, a...)
+       _ = append(
+               s, a...)
+       _ = append(s,
+               a...)
+       _ = append(
+               s,
+               a...)
+       _ = append(s, a...,
+       )
+       _ = append(s,
+               a...,
+       )
+       _ = append(
+               s,
+               a...,
+       )
+}