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>
 // 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)