mirror of
https://github.com/golang/go
synced 2024-11-21 23:34:42 -07:00
go/printer: fix printing of variadic function calls
Fixes #3130. R=golang-dev, gri CC=golang-dev https://golang.org/cl/5697062
This commit is contained in:
parent
5573fa3bc5
commit
eafe86c2df
@ -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)
|
||||
|
||||
|
22
src/pkg/go/printer/testdata/expressions.golden
vendored
22
src/pkg/go/printer/testdata/expressions.golden
vendored
@ -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...,
|
||||
)
|
||||
}
|
||||
|
22
src/pkg/go/printer/testdata/expressions.input
vendored
22
src/pkg/go/printer/testdata/expressions.input
vendored
@ -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...,
|
||||
)
|
||||
}
|
||||
|
22
src/pkg/go/printer/testdata/expressions.raw
vendored
22
src/pkg/go/printer/testdata/expressions.raw
vendored
@ -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...,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user