cmd/go/internal/modload: ensure that modRoot and targetPrefix are initialized in DirImportPath

For #37438

Change-Id: I2e1f47d567842ac5504b7b8ed0b3fba6f92d778b
Reviewed-on: https://go-review.googlesource.com/c/go/+/266340
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Bryan C. Mills 2020-10-28 23:49:54 -04:00
parent 34665c63ff
commit 36d412f754
1 changed files with 2 additions and 1 deletions

View File

@ -520,9 +520,10 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
// DirImportPath returns the effective import path for dir,
// provided it is within the main module, or else returns ".".
func DirImportPath(dir string) string {
if modRoot == "" {
if !HasModRoot() {
return "."
}
LoadModFile(context.TODO())
if !filepath.IsAbs(dir) {
dir = filepath.Join(base.Cwd, dir)