We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
go version go1.23.1 openbsd/amd64
go env
GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/home/richard/.cache/go-build' GOENV='/home/richard/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='openbsd' GOINSECURE='' GOMODCACHE='/home/richard/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='openbsd' GOPATH='/home/richard/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/go' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/local/go/pkg/tool/openbsd_amd64' GOVCS='' GOVERSION='go1.23.1' GODEBUG='' GOTELEMETRY='local' GOTELEMETRYDIR='/home/richard/.config/go/telemetry' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='cc' CXX='c++' CGO_ENABLED='1' GOMOD='/tmp/gotest/baz/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2555655373=/tmp/go-build -gno-record-gcc-switches'
I created a Go module with a non-internal package foo and an internal package foo/internal/bar with the following contents:
foo
foo/internal/bar
$ cat foo/internal/bar/bar.go package bar type Bar struct { X int } $ cat foo/foo.go package foo import "foo/internal/bar" func Foo() bar.Bar { return bar.Bar{X: 42} }
In another Go module, I was able to use the return value of the Foo function with the following code:
Foo
$ cat baz/baz.go package main import "fmt" import "foo" func main() { fmt.Println(foo.Foo().X) } $ cd baz && go run . 42
I expected the compiler to stop me from exposing the internal struct Bar through the non-internal function Foo.
Bar
The text was updated successfully, but these errors were encountered:
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Sorry, something went wrong.
that's working as intended
No branches or pull requests
Go version
go version go1.23.1 openbsd/amd64
Output of
go env
in your module/workspace:What did you do?
I created a Go module with a non-internal package
foo
and an internal packagefoo/internal/bar
with the following contents:What did you see happen?
In another Go module, I was able to use the return value of the
Foo
function with the following code:What did you expect to see?
I expected the compiler to stop me from exposing the internal struct
Bar
through the non-internal functionFoo
.The text was updated successfully, but these errors were encountered: