Skip to content

cmd/go: Contents of internal package can be exposed through non-internal package #71894

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

Closed
codesoap opened this issue Feb 22, 2025 · 2 comments
Closed
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@codesoap
Copy link
Contributor

Go version

go version go1.23.1 openbsd/amd64

Output of go env in your module/workspace:

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'

What did you do?

I created a Go module with a non-internal package foo and an internal package foo/internal/bar with the following contents:

$ 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}
}

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:

$ cat baz/baz.go
package main

import "fmt"
import "foo"

func main() {
        fmt.Println(foo.Foo().X)
}

$ cd baz && go run .
42

What did you expect to see?

I expected the compiler to stop me from exposing the internal struct Bar through the non-internal function Foo.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 22, 2025
@seankhliao
Copy link
Member

that's working as intended

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

3 participants