mirror of
https://github.com/golang/go
synced 2024-11-22 02:54:39 -07:00
gofmt: support for ... after actual arguments
Pending acceptance of the proposed language change. R=rsc CC=golang-dev https://golang.org/cl/2193048
This commit is contained in:
parent
3487495eb0
commit
a6b6142f30
@ -213,7 +213,8 @@ type (
|
|||||||
Fun Expr // function expression
|
Fun Expr // function expression
|
||||||
Lparen token.Position // position of "("
|
Lparen token.Position // position of "("
|
||||||
Args []Expr // function arguments
|
Args []Expr // function arguments
|
||||||
Rparen token.Position // positions of ")"
|
Ellipsis token.Position // position of "...", if any
|
||||||
|
Rparen token.Position // position of ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
// A StarExpr node represents an expression of the form "*" Expression.
|
// A StarExpr node represents an expression of the form "*" Expression.
|
||||||
|
@ -942,8 +942,13 @@ func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
|
|||||||
lparen := p.expect(token.LPAREN)
|
lparen := p.expect(token.LPAREN)
|
||||||
p.exprLev++
|
p.exprLev++
|
||||||
var list vector.Vector
|
var list vector.Vector
|
||||||
for p.tok != token.RPAREN && p.tok != token.EOF {
|
var ellipsis token.Position
|
||||||
|
for p.tok != token.RPAREN && p.tok != token.EOF && !ellipsis.IsValid() {
|
||||||
list.Push(p.parseExpr())
|
list.Push(p.parseExpr())
|
||||||
|
if p.tok == token.ELLIPSIS {
|
||||||
|
ellipsis = p.pos
|
||||||
|
p.next()
|
||||||
|
}
|
||||||
if p.tok != token.COMMA {
|
if p.tok != token.COMMA {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -952,7 +957,7 @@ func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
|
|||||||
p.exprLev--
|
p.exprLev--
|
||||||
rparen := p.expect(token.RPAREN)
|
rparen := p.expect(token.RPAREN)
|
||||||
|
|
||||||
return &ast.CallExpr{fun, lparen, makeExprList(&list), rparen}
|
return &ast.CallExpr{fun, lparen, makeExprList(&list), ellipsis, rparen}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ var validPrograms = []interface{}{
|
|||||||
`package main; func f(func() func() func())` + "\n",
|
`package main; func f(func() func() func())` + "\n",
|
||||||
`package main; func f(...T)` + "\n",
|
`package main; func f(...T)` + "\n",
|
||||||
`package main; func f(float, ...int)` + "\n",
|
`package main; func f(float, ...int)` + "\n",
|
||||||
|
`package main; func f(x int, a ...int) { f(0, a...); f(1, a...,) }` + "\n",
|
||||||
`package main; type T []int; var a []bool; func f() { if a[T{42}[0]] {} }` + "\n",
|
`package main; type T []int; var a []bool; func f() { if a[T{42}[0]] {} }` + "\n",
|
||||||
`package main; type T []int; func g(int) bool { return true }; func f() { if g(T{42}[0]) {} }` + "\n",
|
`package main; type T []int; func g(int) bool { return true }; func f() { if g(T{42}[0]) {} }` + "\n",
|
||||||
`package main; type T []int; func f() { for _ = range []int{T{42}[0]} {} }` + "\n",
|
`package main; type T []int; func f() { for _ = range []int{T{42}[0]} {} }` + "\n",
|
||||||
|
@ -686,7 +686,7 @@ func splitSelector(expr ast.Expr) (body, suffix ast.Expr) {
|
|||||||
case *ast.CallExpr:
|
case *ast.CallExpr:
|
||||||
body, suffix = splitSelector(x.Fun)
|
body, suffix = splitSelector(x.Fun)
|
||||||
if body != nil {
|
if body != nil {
|
||||||
suffix = &ast.CallExpr{suffix, x.Lparen, x.Args, x.Rparen}
|
suffix = &ast.CallExpr{suffix, x.Lparen, x.Args, x.Ellipsis, x.Rparen}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case *ast.IndexExpr:
|
case *ast.IndexExpr:
|
||||||
@ -847,6 +847,9 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi
|
|||||||
p.expr1(x.Fun, token.HighestPrec, depth, 0, multiLine)
|
p.expr1(x.Fun, token.HighestPrec, depth, 0, multiLine)
|
||||||
p.print(x.Lparen, token.LPAREN)
|
p.print(x.Lparen, token.LPAREN)
|
||||||
p.exprList(x.Lparen, x.Args, depth, commaSep|commaTerm, multiLine, x.Rparen)
|
p.exprList(x.Lparen, x.Args, depth, commaSep|commaTerm, multiLine, x.Rparen)
|
||||||
|
if x.Ellipsis.IsValid() {
|
||||||
|
p.print(x.Ellipsis, token.ELLIPSIS)
|
||||||
|
}
|
||||||
p.print(x.Rparen, token.RPAREN)
|
p.print(x.Rparen, token.RPAREN)
|
||||||
|
|
||||||
case *ast.CompositeLit:
|
case *ast.CompositeLit:
|
||||||
|
@ -169,6 +169,13 @@ func _() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func f(x int, args ...int) {
|
||||||
|
f(0, args...)
|
||||||
|
f(1, args)
|
||||||
|
f(2, args[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
_ = T{}
|
_ = T{}
|
||||||
_ = struct{}{}
|
_ = struct{}{}
|
||||||
|
@ -169,6 +169,13 @@ func _() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func f(x int, args ...int) {
|
||||||
|
f(0, args...)
|
||||||
|
f(1, args)
|
||||||
|
f(2, args[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
_ = T{}
|
_ = T{}
|
||||||
_ = struct{}{}
|
_ = struct{}{}
|
||||||
|
7
src/pkg/go/printer/testdata/expressions.raw
vendored
7
src/pkg/go/printer/testdata/expressions.raw
vendored
@ -169,6 +169,13 @@ func _() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func f(x int, args ...int) {
|
||||||
|
f(0, args...)
|
||||||
|
f(1, args)
|
||||||
|
f(2, args[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
_ = T{}
|
_ = T{}
|
||||||
_ = struct{}{}
|
_ = struct{}{}
|
||||||
|
Loading…
Reference in New Issue
Block a user