Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go list mangles absolute paths weirdly #29709

segevfiner opened this issue Jan 12, 2019 · 3 comments

cmd/go: go list mangles absolute paths weirdly #29709

segevfiner opened this issue Jan 12, 2019 · 3 comments


Copy link

@segevfiner segevfiner commented Jan 12, 2019

What version of Go are you using (go version)?

$ go version
go version go1.11.4 windows/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=<snip>\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=<snip>\go
set GOROOT=<snip>\go
set GOTOOLDIR=<snip>\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=<snip>\AppData\Local\Temp\go-build323227346=/tmp/go-build -gno-record-gcc-switches

What did you do?

  1. Create foo/main.go somewhere outside GOPATH:
package main

func main() {

  1. cd to that directory and run go list.

What did you expect to see?

The full absolute path to the directory:


What did you see instead?

The full absolute path to the directory mangled:


This comment has been minimized.

Copy link

@novasharper novasharper commented Jan 12, 2019

This is actually the valid output

// dirToImportPath returns the pseudo-import path we use for a package
// outside the Go path. It begins with _/ and then contains the full path
// to the directory. If the package lives in c:\home\gopher\my\pkg then
// the pseudo-import path is _/c_/home/gopher/my/pkg.
// Using a pseudo-import path like this makes the ./ imports no longer
// a special case, so that all the code to deal with ordinary imports works
// automatically.
func dirToImportPath(dir string) string {
	return pathpkg.Join("_", strings.Map(makeImportValid, filepath.ToSlash(dir)))


@dmitshur dmitshur changed the title go list mangles absolute paths weirdly cmd/go: go list mangles absolute paths weirdly Jan 13, 2019

This comment has been minimized.

Copy link

@bcmills bcmills commented Jan 14, 2019

In GOPATH mode you cannot import things that reside outside of GOPATH (except, perhaps, as relative imports). So it shouldn't really matter what the actual import path is: it only shows up in a few places (e.g. reflect).

In module mode, the go.mod file in (a parent of) the current directory defines its import path.
Given that, I don't think this is worth changing at this point.

@bcmills bcmills closed this Jan 14, 2019

This comment has been minimized.

Copy link
Contributor Author

@segevfiner segevfiner commented Jan 14, 2019

The only reason I saw this was accidently placing something outside GOPATH that isn't a module and having errors in vscode-go due to the output of go list. It's your call whether you actually care about this or not...

@golang golang locked and limited conversation to collaborators Jan 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.