I have found an odd behavior and am not sure if it is a bug. Before raising an issue at GitHub - golang/go: The Go programming language, I’m interested to hear if you think this is a bug. Suppose I have two packages in my module:
foo/internal/bar
: This package exportstype MyBar struct {...}
foo
: This package importsfoo/internal/bar
and definesfunc Foo() bar.MyBar {...}
With this “package-layout” go vet
has no complaints. I can also use the Foo
function from another module and, e.g., print its return value. I feel like it should not be possible to return an internal struct from a non-internal function, because this circumvents the usual restriction of an internal struct.
Do you think this is a bug as well or is there any good reason for the current behavior?