Skip to content

reflect: Anonymous fields and embedded fields #4514

@nsf

Description

@nsf
The type reflect.StructField has a field called "Anonymous". But frankly there
are no anonymous fields in Go, at least they are not what "reflect" thinks
they are. Reflect package puts "true" into that field on embedded fields,
which are not anonymous, because their name matches their type name. And real anonymous
fields:

type X struct {
    _ io.Reader
    _ io.Reader
}

are not marked as such. And that makes that particular case a source of terminology
confusion.

P.S. As a somewhat related note, it would be nice to be able to distinguish between a
user-defined method (that is written explicitly in the source code) and a automatically
generated method which was inherited from an embedded field. Should I create a separate
issue on that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions