Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

"(*bufferChecker).DataInt16" considered an exported/public method #63

Open
emidoots opened this issue Dec 14, 2015 · 4 comments
Open

"(*bufferChecker).DataInt16" considered an exported/public method #63

emidoots opened this issue Dec 14, 2015 · 4 comments

Comments

@emidoots
Copy link
Member

srclib-go seems to define (*bufferChecker).DataInt16 as an exported/public method. I'm not exactly sure whether or not this is the case or not (e.g. reflect package does consider this to be true, but godoc does not). Is this the correct behavior?

@dmitshur
Copy link
Contributor

Hmm, this is pretty subtle and depends on the exact definitions.

As far as I see, it is an exported method, but the type it's associated with is not exported.

If an exported func returns this unexported type, then its exported methods can be accessed, but its unexported methods cannot be:

package foo

func ExportedFuncThatReturnsUnexportedBufferChecker() *bufferChecker { ... }
package bar

import "foo"

func main() {
    bc := ExportedFuncThatReturnsUnexportedBufferChecker()
    bc.DataInt16() // Ok.
}

@dmitshur
Copy link
Contributor

but godoc does not

In what way does godoc consider it not to be exported? Can you elaborate?

@emidoots
Copy link
Member Author

For example, https://godoc.org/github.com/slimsag/gfx/debug - This page shows only two exported functions:

func Checker(c gfx.Context) gfx.Context
func Context(c gfx.Context) gfx.Context

However, the data from srclib-go for graph.Def.Exported (see here) is inclusive of exported methods on non-exported types. The docs do not state directly how this situation should be interpreted:

    // Exported is whether this def is part of a source unit's
    // public API. For example, in Java a "public" field is
    // Exported.
    Exported bool `protobuf:"varint,7,opt,name=exported,proto3" json:"Exported,omitempty"`

The question here is: should Exported be considered inclusive of (*foo) Bar, or not? In my case (api docs), I don't want it to be -- but I can imagine situations where you would want it to be, too.

@dmitshur
Copy link
Contributor

I see. Seen from that light, I think I'd expect (*foo) Bar to have value Exported of false. The method is exported, but since its type is unexported, that should mean the Def is not exported either. It's a not a part of the source unit's public API.

So I'm inclined to think current behavior is not correct.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants