Skip to content

cmd/go: doc: doesn't show embedded struct's methods #69596

Open
@gucio321

Description

@gucio321

Proposal Details

Hi!
I was recently using a new GO module in my project.
There was code like this:

type (
   A struct {}
   B struct { *A }
)

func (*A) Foo() {}

Tybe B however was a large struct with many methods and exported fields.
I had a code example that used method Foo and I just wanted to know more about i.
I used go doc B.Foo but it said doc: no method or field B.Foo in package.

I suppose, that because call like this is 100% possible &B{}.Foo(), above go doc call should return documentation for Foo

Activity

added this to the Proposal milestone on Sep 23, 2024
gucio321

gucio321 commented on Sep 23, 2024

@gucio321
ContributorAuthor

#1000 seems similar but it was in 2010 and there was a regression since that (?)

moved this to Incoming in Proposalson Sep 23, 2024
zigo101

zigo101 commented on Sep 23, 2024

@zigo101

As #1000 was ever fixed, so this should not be a proposal?

gucio321

gucio321 commented on Sep 23, 2024

@gucio321
ContributorAuthor

@zigo101 so a bug? Could you change pls? Or should i open another issue as a bug?

ianlancetaylor

ianlancetaylor commented on Sep 23, 2024

@ianlancetaylor
Contributor

I haven't verified this, but as reported it's just a bug. This issue is fine as is. Thanks.

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
and removed on Sep 23, 2024
changed the title [-]proposal: cmd/go: doc: doesn't show embeded struct's methods[/-] [+]cmd/go: doc: doesn't show embedded struct's methods[/+] on Sep 23, 2024
codekitchen

codekitchen commented on Sep 25, 2024

@codekitchen
Contributor

I investigated this a bit and found that this change in behavior, hiding methods from exported embeds, was intentional in response to #2791 . So I don't think this qualifies as a bug?

Background info from my investigation:

The current src/go/doc package intentionally hides methods from exported embeds by default. It does include unexported embedded methods, for instance:

type (
    a struct{}
    B struct { *a }
)

func (*a) Foo() {}

go doc B.Foo will show the method in this case, because a is not exported.

To revert back to showing exported embedded methods too, the go doc command at src/cmd/doc could pass the AllMethods mode flag to src/go/doc

zigo101

zigo101 commented on Sep 26, 2024

@zigo101

The current src/go/doc package intentionally hides methods from exported embeds by default. It does include unexported embedded methods,

The design difference here looks unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @codekitchen@ianlancetaylor@gopherbot@zigo101@gucio321

        Issue actions

          cmd/go: doc: doesn't show embedded struct's methods · Issue #69596 · golang/go