Skip to content

Commit 9c9b32f

Browse files
committed
go/internal/load: fix that bad error message for local imports in module
mode In module mode, if an import statement refers to a relative path it is currently supposed to fail with relative import not supported However, we seem to be missing test coverage for that error message, and the actual error that is printed for that case is substantially different
1 parent 8a7ee4c commit 9c9b32f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/cmd/go/internal/load/pkg.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ func loadImport(ctx context.Context, opts PackageOpts, pre *preload, path, srcDi
754754
var err error
755755
if path == "." {
756756
err = ImportErrorf(path, "%s: cannot import current directory", path)
757+
} else if build.IsLocalImport(path) {
758+
err = ImportErrorf(path, "%s: relative import not supported", path)
757759
} else {
758760
err = ImportErrorf(path, "local import %q in non-local package", path)
759761
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
! go build
2+
stderr 'main.go:4:2: ./foo: relative import not supported'
3+
4+
-- foo/foo.go --
5+
package foo
6+
-- go.mod --
7+
module example.com/m
8+
9+
go 1.17
10+
-- main.go --
11+
package main
12+
13+
import (
14+
_ "./foo"
15+
)
16+
17+
func main() {}

0 commit comments

Comments
 (0)