src/go/ast/ast.go | 8 +++++--- diff --git a/src/go/ast/ast.go b/src/go/ast/ast.go index d73c323178dbd7b64d4009d3d44da75ea8848890..fd109507b8b73f7feba5ff7ebe8e1e1e8a67ad84 100644 --- a/src/go/ast/ast.go +++ b/src/go/ast/ast.go @@ -153,10 +153,12 @@ // A Field represents a Field declaration list in a struct type, // a method list in an interface type, or a parameter/result declaration // in a signature. +// Field.Names is nil for unnamed parameters (parameter lists which only contain types) +// and embedded struct fields. In the latter case, the field name is the type name. // type Field struct { Doc *CommentGroup // associated documentation; or nil - Names []*Ident // field/method/parameter names; or nil if anonymous field + Names []*Ident // field/method/parameter names; or nil Type Expr // field/method/parameter type Tag *BasicLit // field tag; or nil Comment *CommentGroup // line comments; or nil @@ -207,14 +209,14 @@ } return token.NoPos } -// NumFields returns the number of (named and anonymous fields) in a FieldList. +// NumFields returns the number of parameters or struct fields represented by a FieldList. func (f *FieldList) NumFields() int { n := 0 if f != nil { for _, g := range f.List { m := len(g.Names) if m == 0 { - m = 1 // anonymous field + m = 1 } n += m }