Skip to content

Commit 36d412f

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Reviewed-by: Michael Matloob <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Bryan C. Mills <[email protected]>
1 parent 34665c6 commit 36d412f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/cmd/go/internal/modload/load.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,10 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
520520
// DirImportPath returns the effective import path for dir,
521521
// provided it is within the main module, or else returns ".".
522522
func DirImportPath(dir string) string {
523-
if modRoot == "" {
523+
if !HasModRoot() {
524524
return "."
525525
}
526+
LoadModFile(context.TODO())
526527

527528
if !filepath.IsAbs(dir) {
528529
dir = filepath.Join(base.Cwd, dir)

0 commit comments

Comments
 (0)