-
Notifications
You must be signed in to change notification settings - Fork 18k
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: 'go run x.go' should not be able to import internal packages #10478
Comments
It seems like this change would make it impossible for one-off generator code to use internal packages. Supposing that this is fixed as you suggest but also that we did want to add a compress/flate/internal/huffman package, how could we implement compress/flate/gen.go instead? |
Yeah, I also used this capability before.
I sometimes wrote one-off programs to test something in the cmd/internal
packages.
I think it's ok to leave this hole esp. it requires that you place the
source code in a
directory where a normal package placed there could import the internal
package.
|
I'm sorry, but the fact that people use the bug does not make it less of a bug. Internal means internal. |
Russ, on the one hand you want Personally, I thought that the "a separate workspace" aspect was an implementation detail, not the public interface, and that |
@rsc I agree that "go run" and "go build" need to be made internal-aware. It's certainly a bug that "go run $GOPATH/src/foo/x.go" currently works even if foo/x.go imports internal packages from the standard library like net/http/internal. It's just not obvious to me that "go run $GOROOT/src/net/http/x.go" should fail if net/http/x.go imports net/http/internal, because it would complicate some seemingly reasonable use cases for mixing "internal" and "go generate". A simple concrete proposal would be that if the files passed to "go build" or "go run" are all within the same directory, then they should be allowed to import internal packages just as normal package code within that same directory could. For example, $GOROOT/src/net/http/x.go could import net/http/internal, but not $GOROOT/src/cmd/internal/gc. The proposal could be extended to files spread across multiple directories too, but I'm not sure there's a need. |
Will let this stand unless more evidence accumulates that this is a mistake. |
Commands built or run by listing Go source file names on the command line are treated as a separate workspace from $GOROOT and $GOPATH. The handling of /internal/ is not doing that, meaning that if you put an x.go in, say, $GOROOT/src/http and run 'go run x.go', it can import http/internal. That's a mistake.
The text was updated successfully, but these errors were encountered: