Fixes #51604.
Change-Id: I3bc86652c62d2b329d9c2db5ea443d56cf17f8d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/418094
Reviewed-by: Nooras Saba <saba@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
var mains []*Package
for _, pkg := range pkgs {
- if pkg.Name == "main" {
+ if pkg.Name == "main" || (pkg.Name == "" && pkg.Error != nil) {
treatAsMain[pkg.ImportPath] = true
mains = append(mains, pkg)
continue
if pkg == "" {
if inWorkspaceMode() {
if mr := findModuleRoot(absDir); mr != "" {
- return "", fmt.Errorf("directory %s is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using go work use %s", base.ShortPath(absDir), base.ShortPath(mr))
+ return "", fmt.Errorf("directory %s is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use %s", base.ShortPath(absDir), base.ShortPath(mr))
}
return "", fmt.Errorf("directory %s outside modules listed in go.work or their selected dependencies", base.ShortPath(absDir))
}
stderr 'pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies'
! go list ./a/c
-stderr 'directory a[\\/]c is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using go work use a'
+stderr 'directory a[\\/]c is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use a'
+
+! go install ./a/c
+stderr 'directory a[\\/]c is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use a'
+
+cd a/c
+! go run .
+stderr 'directory . is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use \.\.'
-- go.work --
go 1.18
-- a/a.go --
package a
-- a/c/c.go --
-package c
+package main
-- b/go.mod --
module example.com/b