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 · 6 comments
Open

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

wozz opened this issue Apr 22, 2020 · 6 comments
Labels
Documentation GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@wozz
Copy link

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 GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 22, 2020
@andybons andybons added this to the Unplanned milestone Apr 22, 2020
@andybons
Copy link
Member

@bcmills @jayconrod @matloob

@bcmills
Copy link
Contributor

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
Contributor

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 added Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Apr 22, 2020
@bcmills bcmills modified the milestones: Unplanned, Backlog Apr 22, 2020
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 22, 2020
@abemotion
Copy link

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 ?

@gopherbot
Copy link

Change https://golang.org/cl/243398 mentions this issue: cmd/go: improve gopath documentation about internal directories

@gopherbot
Copy link

Change https://go.dev/cl/475640 mentions this issue: cmd/go: move module info up in GOPATH help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants