`unexportedField.*int.*Comment on line with unexported field.`,
`ExportedEmbeddedType.*Comment on line with exported embedded field.`,
`\*ExportedEmbeddedType.*Comment on line with exported embedded \*field.`,
+ `\*qualified.ExportedEmbeddedType.*Comment on line with exported embedded \*selector.field.`,
`unexportedType.*Comment on line with unexported embedded field.`,
`\*unexportedType.*Comment on line with unexported embedded \*field.`,
`io.Reader.*Comment on line with embedded Reader.`,
for _, field := range fields.List {
names := field.Names
if len(names) == 0 {
- // Embedded type. Use the name of the type. It must be of type ident or *ident.
+ // Embedded type. Use the name of the type. It must be of the form ident or
+ // pkg.ident (for structs and interfaces), or *ident or *pkg.ident (structs only).
// Nothing else is allowed.
- switch ident := field.Type.(type) {
+ ty := field.Type
+ if se, ok := field.Type.(*ast.StarExpr); !isInterface && ok {
+ // The form *ident or *pkg.ident is only valid on
+ // embedded types in structs.
+ ty = se.X
+ }
+ switch ident := ty.(type) {
case *ast.Ident:
if isInterface && ident.Name == "error" && ident.Obj == nil {
// For documentation purposes, we consider the builtin error
continue
}
names = []*ast.Ident{ident}
- case *ast.StarExpr:
- // Must have the form *identifier.
- // This is only valid on embedded types in structs.
- if ident, ok := ident.X.(*ast.Ident); ok && !isInterface {
- names = []*ast.Ident{ident}
- }
case *ast.SelectorExpr:
// An embedded type may refer to a type in another package.
names = []*ast.Ident{ident.Sel}
// Comment about exported type.
type ExportedType struct {
// Comment before exported field.
- ExportedField int // Comment on line with exported field.
- unexportedField int // Comment on line with unexported field.
- ExportedEmbeddedType // Comment on line with exported embedded field.
- *ExportedEmbeddedType // Comment on line with exported embedded *field.
- unexportedType // Comment on line with unexported embedded field.
- *unexportedType // Comment on line with unexported embedded *field.
- io.Reader // Comment on line with embedded Reader.
- error // Comment on line with embedded error.
+ ExportedField int // Comment on line with exported field.
+ unexportedField int // Comment on line with unexported field.
+ ExportedEmbeddedType // Comment on line with exported embedded field.
+ *ExportedEmbeddedType // Comment on line with exported embedded *field.
+ *qualified.ExportedEmbeddedType // Comment on line with exported embedded *selector.field.
+ unexportedType // Comment on line with unexported embedded field.
+ *unexportedType // Comment on line with unexported embedded *field.
+ io.Reader // Comment on line with embedded Reader.
+ error // Comment on line with embedded error.
}
// Comment about exported method.