lbrack := p.expect(token.LBRACK)
var len ast.Expr
if ellipsisOk && p.tok == token.ELLIPSIS {
- len = &ast.Ellipsis{p.pos}
+ len = &ast.Ellipsis{p.pos, nil}
p.next()
} else if p.tok != token.RBRACK {
len = p.parseExpr()
if ellipsisOk && p.tok == token.ELLIPSIS {
pos := p.pos
p.next()
+ typ := p.tryType()
if p.tok != token.RPAREN {
- // "..." always must be at the very end of a parameter list
- p.Error(pos, "expected type, found '...'")
+ p.Error(pos, "can use '...' for last parameter only")
}
- return &ast.Ellipsis{pos}
+ return &ast.Ellipsis{pos, typ}
}
return p.tryType()
}
// parameter list or the "..." length in an array type.
//
Ellipsis struct {
- token.Position // position of "..."
+ token.Position // position of "..."
+ Elt Expr // ellipsis element type (parameter lists only)
}
// A BasicLit node represents a literal of basic type.
return nil, err
}
- scope := ast.NewScope(nil)
+ var scope *ast.Scope = nil // for now tracking of declarations is disabled
pkgs := make(map[string]*ast.Package)
for i := 0; i < len(list); i++ {
entry := &list[i]
p.mode = mode
p.trace = mode&Trace != 0 // for convenience (p.trace is used frequently)
if scope != nil {
- // Disabled for now. Causes error with "godoc http":
- // parser.parseDir: src/pkg/http/server.go:159:16: 'Write' declared already at src/pkg/http/request.go:140:21 (and 4 more errors)
-
- // p.checkDecl = true
+ p.checkDecl = true
} else {
scope = ast.NewScope(nil) // provide a dummy scope
}
lbrack := p.expect(token.LBRACK)
var len ast.Expr
if ellipsisOk && p.tok == token.ELLIPSIS {
- len = &ast.Ellipsis{p.pos}
+ len = &ast.Ellipsis{p.pos, nil}
p.next()
} else if p.tok != token.RBRACK {
len = p.parseExpr()
if ellipsisOk && p.tok == token.ELLIPSIS {
pos := p.pos
p.next()
+ typ := p.tryType()
if p.tok != token.RPAREN {
- // "..." always must be at the very end of a parameter list
- p.Error(pos, "expected type, found '...'")
+ p.Error(pos, "can use '...' for last parameter only")
}
- return &ast.Ellipsis{pos}
+ return &ast.Ellipsis{pos, typ}
}
return p.tryType()
}
p.next()
} else if p.tok == token.IDENT {
ident = p.parseIdent(ast.Pkg)
+ // TODO(gri) Make sure the ident is not already declared in the
+ // package scope. Also, cannot add the same name to
+ // the package scope later.
p.declIdent(p.fileScope, ident)
}
`package main; func main() { _ = (<-chan int)(x) }` + "\n",
`package main; func main() { _ = (<-chan <-chan int)(x) }` + "\n",
`package main; func f(func() func() func())` + "\n",
+ `package main; func f(...)` + "\n",
+ `package main; func f(float, ...int)` + "\n",
}
case *ast.Ellipsis:
p.print(token.ELLIPSIS)
+ if x.Elt != nil {
+ p.expr(x.Elt, multiLine)
+ }
case *ast.ArrayType:
p.print(token.LBRACK)
var _ = x // comment
}
+
+
+// ellipsis parameters
+func _(...)
+func _(...int)
+func _(...*int)
+func _(...[]int)
+func _(...struct{})
+func _(bool, ...interface{})
+func _(bool, ...func())
+func _(bool, ...func(...))
+func _(bool, ...map[string]int)
+func _(bool, ...chan int)
+
+func _(b bool, x ...)
+func _(b bool, x ...int)
+func _(b bool, x ...*int)
+func _(b bool, x ...[]int)
+func _(b bool, x ...struct{})
+func _(x ...interface{})
+func _(x ...func())
+func _(x ...func(...))
+func _(x ...map[string]int)
+func _(x ...chan int)
var _ // comment
= x;
}
+
+
+// ellipsis parameters
+func _(...)
+func _(...int)
+func _(...*int)
+func _(...[]int)
+func _(...struct{})
+func _(bool, ...interface{})
+func _(bool, ...func())
+func _(bool, ...func(...))
+func _(bool, ...map[string]int)
+func _(bool, ...chan int)
+
+func _(b bool, x ...)
+func _(b bool, x ...int)
+func _(b bool, x ...*int)
+func _(b bool, x ...[]int)
+func _(b bool, x ...struct{})
+func _(x ...interface{})
+func _(x ...func())
+func _(x ...func(...))
+func _(x ...map[string]int)
+func _(x ...chan int)