From 36d412f7548d90f4764c780a6f7d7da04bb90a9e Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 28 Oct 2020 23:49:54 -0400 Subject: [PATCH] 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 Reviewed-by: Jay Conrod Reviewed-by: Michael Matloob TryBot-Result: Go Bot Trust: Bryan C. Mills --- src/cmd/go/internal/modload/load.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index f9c468c8b2..0a84a1765a 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -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) -- 2.48.1