// A CallExpr node represents an expression followed by an argument list.
CallExpr struct {
- Fun Expr // function expression
- Lparen token.Position // position of "("
- Args []Expr // function arguments
- Rparen token.Position // positions of ")"
+ Fun Expr // function expression
+ Lparen token.Position // position of "("
+ Args []Expr // function arguments
+ Ellipsis token.Position // position of "...", if any
+ Rparen token.Position // position of ")"
}
// A StarExpr node represents an expression of the form "*" Expression.
lparen := p.expect(token.LPAREN)
p.exprLev++
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())
+ if p.tok == token.ELLIPSIS {
+ ellipsis = p.pos
+ p.next()
+ }
if p.tok != token.COMMA {
break
}
p.exprLev--
rparen := p.expect(token.RPAREN)
- return &ast.CallExpr{fun, lparen, makeExprList(&list), rparen}
+ return &ast.CallExpr{fun, lparen, makeExprList(&list), ellipsis, rparen}
}
`package main; func f(func() func() func())` + "\n",
`package main; func f(...T)` + "\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; 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",
case *ast.CallExpr:
body, suffix = splitSelector(x.Fun)
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
}
case *ast.IndexExpr:
p.expr1(x.Fun, token.HighestPrec, depth, 0, multiLine)
p.print(x.Lparen, token.LPAREN)
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)
case *ast.CompositeLit:
}
+func f(x int, args ...int) {
+ f(0, args...)
+ f(1, args)
+ f(2, args[0])
+}
+
+
func _() {
_ = T{}
_ = struct{}{}
}
+func f(x int, args ...int) {
+ f(0, args...)
+ f(1, args)
+ f(2, args[0])
+}
+
+
func _() {
_ = T{}
_ = struct{}{}
}
+func f(x int, args ...int) {
+ f(0, args...)
+ f(1, args)
+ f(2, args[0])
+}
+
+
func _() {
_ = T{}
_ = struct{}{}