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: document 'internal' package visibility for module mode #38579

Open
wozz opened this issue Apr 22, 2020 · 4 comments
Open

cmd/go: document 'internal' package visibility for module mode #38579

wozz opened this issue Apr 22, 2020 · 4 comments

Comments

@wozz
Copy link

@wozz wozz commented Apr 22, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.2

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

https://play.golang.org/p/tnQdiMMclCx

What did you expect to see?

I expected the program to compile.

What did you see instead?

prog.go:7:2: use of internal package example.com/v2/internal/foo not allowed

@andybons andybons changed the title internal package imports across modules fails after major version upgrade cmd/go: internal package imports across modules fails after major version upgrade Apr 22, 2020
@andybons andybons added this to the Unplanned milestone Apr 22, 2020
@andybons
Copy link
Member

@andybons andybons commented Apr 22, 2020

@bcmills
Copy link
Member

@bcmills bcmills commented Apr 22, 2020

The error message here is correct.

In order for an internal package to be imported, the package containing the import statement must have the same prefix as the internal package up to the last /internal/ element.

In this case, that prefix is example.com/v2, which is not a prefix of example.com/test.

If you want an internal package to be shared between example.com/test and example.com/v2, it must be within module example.com (or, rarely, some other module that begins with example.com/internal — but I would not recommend that if you can avoid it).

@bcmills
Copy link
Member

@bcmills bcmills commented Apr 22, 2020

This behavior is documented in go help gopath, although it appears that we need to update that documentation to be more explicit about how it maps to module mode.

@bcmills bcmills changed the title cmd/go: internal package imports across modules fails after major version upgrade cmd/go: document 'internal' package visibility for module mode Apr 22, 2020
@bcmills bcmills modified the milestones: Unplanned, Backlog Apr 22, 2020
@abemotion
Copy link

@abemotion abemotion commented Apr 25, 2020

Each different major version (v1, v2, and so on) of a Go module uses a different module path.
In the example, v2 of foo is no longer foo: instead, it is identified by the module path foo/v2.

Adding This documentation to go help gopath is better ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.