]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix import current directory error message
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>
Sat, 27 Apr 2019 11:55:49 +0000 (18:55 +0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 14 May 2019 15:00:43 +0000 (15:00 +0000)
Fixes #14683

Change-Id: I62c429e4fcc2f20a94d3db8c1f0ca587252c07a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/174130
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/load/pkg.go

index f34339ab5715bd5fe82d808ec4dfd5960751c0b3..1ec82ad532d863a4095c23967b844040ae923826 100644 (file)
@@ -3626,7 +3626,7 @@ func TestImportLocal(t *testing.T) {
                var _ = x.X
        `)
        tg.runFail("build", "dir/x")
-       tg.grepStderr("local import.*in non-local package", "did not diagnose local import")
+       tg.grepStderr("cannot import current directory", "did not diagnose import current directory")
 
        // ... even in a test.
        tg.tempFile("src/dir/x/xx.go", `package x
@@ -3639,7 +3639,7 @@ func TestImportLocal(t *testing.T) {
        `)
        tg.run("build", "dir/x")
        tg.runFail("test", "dir/x")
-       tg.grepStderr("local import.*in non-local package", "did not diagnose local import")
+       tg.grepStderr("cannot import current directory", "did not diagnose import current directory")
 
        // ... even in an xtest.
        tg.tempFile("src/dir/x/xx.go", `package x
@@ -3652,7 +3652,7 @@ func TestImportLocal(t *testing.T) {
        `)
        tg.run("build", "dir/x")
        tg.runFail("test", "dir/x")
-       tg.grepStderr("local import.*in non-local package", "did not diagnose local import")
+       tg.grepStderr("cannot import current directory", "did not diagnose import current directory")
 }
 
 func TestGoGetInsecure(t *testing.T) {
index 7ee335c5d61c2e4f9b6b92148dc36e9877020c16..b1e9fc9ff5adfffdc65d48bc3d5fb464d2d870b7 100644 (file)
@@ -544,9 +544,13 @@ func loadImport(pre *preload, path, srcDir string, parent *Package, stk *ImportS
 
        if p.Internal.Local && parent != nil && !parent.Internal.Local {
                perr := *p
+               errMsg := fmt.Sprintf("local import %q in non-local package", path)
+               if path == "." {
+                       errMsg = "cannot import current directory"
+               }
                perr.Error = &PackageError{
                        ImportStack: stk.Copy(),
-                       Err:         fmt.Sprintf("local import %q in non-local package", path),
+                       Err:         errMsg,
                }
                return setErrorPos(&perr, importPos)
        }