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: inconsistent handling of package main importing another package main #5198
Labels
Milestone
Comments
The go tool assumes that a package main is an executable, and this is by design. The use of "package main" is a signal to the go tool that you want to compile a command, not a package object. The spec allows importing another package main to allow for testing of package main. For instance: $ cat main.go package main import "fmt" func Hello() string { return "Hi" } func main() { fmt.Println(Hello()) } $ cat main_test.go package main import "testing" func TestHello(t *testing.T) { want := "Hi" if got := Hello(); got != want { t.Errorf("Hello() = %q, want %q", got, want) } } Behind the scenes, when you run "go test", a new main package is constructed that imports the package main that is under test. Status changed to WorkingAsIntended. |
Okay, so maybe at the very least the go tool should reject such programs consistently. This scenario: % go install ./a % touch a/a.go % go install ./a # foo/a a/a.go:3: can't find import: "foo/b" % is surprising. The go tool should have either errored out on the first run, or succeed on both; it should do something consistent. It feels buggy that a mere touch breaks the build. |
I believe this is related to this issue, https://golang.org/issue/3417. |
Status changed to Duplicate. Merged into issue #4210. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: