Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gucio321 opened this issue Sep 23, 2024 · 7 comments
Open

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

gucio321 opened this issue Sep 23, 2024 · 7 comments
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@gucio321
Copy link
Contributor

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

@gopherbot gopherbot added this to the Proposal milestone Sep 23, 2024
@gucio321
Copy link
Contributor Author

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

@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Sep 23, 2024
@zigo101
Copy link

zigo101 commented Sep 23, 2024

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

@gucio321
Copy link
Contributor Author

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

@ianlancetaylor
Copy link
Member

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

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Proposal labels Sep 23, 2024
@ianlancetaylor ianlancetaylor changed the title proposal: cmd/go: doc: doesn't show embeded struct's methods cmd/go: doc: doesn't show embedded struct's methods Sep 23, 2024
@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Backlog Sep 23, 2024
@codekitchen
Copy link
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
Copy link

zigo101 commented Sep 26, 2024

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
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants