diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go index cd5e075c16c..2205f633f1d 100644 --- a/src/pkg/go/printer/nodes.go +++ b/src/pkg/go/printer/nodes.go @@ -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) diff --git a/src/pkg/go/printer/testdata/expressions.golden b/src/pkg/go/printer/testdata/expressions.golden index 95fdd95ffbb..45fa4d97a4a 100644 --- a/src/pkg/go/printer/testdata/expressions.golden +++ b/src/pkg/go/printer/testdata/expressions.golden @@ -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..., + ) +} diff --git a/src/pkg/go/printer/testdata/expressions.input b/src/pkg/go/printer/testdata/expressions.input index d1131498352..f545c66057c 100644 --- a/src/pkg/go/printer/testdata/expressions.input +++ b/src/pkg/go/printer/testdata/expressions.input @@ -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..., + ) +} diff --git a/src/pkg/go/printer/testdata/expressions.raw b/src/pkg/go/printer/testdata/expressions.raw index 3442ba9b950..87a4b00836d 100644 --- a/src/pkg/go/printer/testdata/expressions.raw +++ b/src/pkg/go/printer/testdata/expressions.raw @@ -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..., + ) +}