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: wrong output for a non-canonical import path #16954

Closed
benma opened this issue Sep 1, 2016 · 7 comments
Closed

cmd/go: wrong output for a non-canonical import path #16954

benma opened this issue Sep 1, 2016 · 7 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@benma
Copy link

benma commented Sep 1, 2016

When importing a package with a non-canonical import path (ending in a slash), the compiler error tells you about it and points you to the offending import.

If the imported package imports a vendored package (and only then), the compiler error points to the wrong location and the error text is wrong too. See below in the expected/actual output.

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

go version go1.7 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/opt/go"
GORACE=""
GOROOT="/opt/go_dist/go"
GOTOOLDIR="/opt/go_dist/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build865793365=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLEgo build ./...
# github.com/benma/test/lib/
lib/lib.go:3: non-canonical import path "github.com/benma/test//vendor/vendoredlib" (should be "github.com/benma/test/vendor/vendoredlib")
lib/lib.go:3: can't find import: "github.com/benma/test//vendor/vendoredlib"
D="1"

What did you do?

go build ./... in a project with those three files inside:

main.go:

package main

import "github.com/benma/test/lib/" // error here, but compiler points somewhere else!

var _ = lib.Foo

func main() {}

lib/lib.go:

package lib

import "vendoredlib"

var Foo = vendoredlib.Foo

vendor/vendoredlib/vendoredlib.go:

package vendoredlib

var Foo = true

What did you expect to see?

Compiler error like this:

go build ./...
# github.com/benma/test
./main.go:3: non-canonical import path "github.com/benma/test/lib/" (should be "github.com/benma/test/lib")
./main.go:3: can't find import: "github.com/benma/test/lib/"

What did you see instead?

go build ./...
# github.com/benma/test/lib/
lib/lib.go:3: non-canonical import path "github.com/benma/test//vendor/vendoredlib" (should be "github.com/benma/test/vendor/vendoredlib")
lib/lib.go:3: can't find import: "github.com/benma/test//vendor/vendoredlib"

Note that the error points to an import in lib.go, where everything is correct, instead of to main.go. Also the error text talks about github.com/benma/test//vendor/vendoredlib vs github.com/benma/test/vendor/vendoredlib, where the actual import in lib.go:3 is simply import "vendoredlib".

On a related note, shouldn't goimports fix wrong imports like that (and simply strip the trailing slash)?

@odeke-em odeke-em changed the title Wrong compiler output for a non-canonical import path cmd/compile: wrong output for a non-canonical import path Sep 1, 2016
@odeke-em
Copy link
Member

odeke-em commented Sep 2, 2016

/cc @josharian @randall77

@randall77
Copy link
Contributor

@griesemer @mdempsky

@quentinmit quentinmit added this to the Go1.8 milestone Sep 6, 2016
@chrisportela
Copy link

I've also run in to this issue

$ go version
go version go1.7.1 darwin/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/cp/Code/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lg/nhm1xy416vz46g5v8blnnsb80000gn/T/go-build016907633=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
$ go build ./cmd/...
# github.com/cmpis/project//vendor/github.com/jinzhu/gorm
vendor/github.com/jinzhu/gorm/model_struct.go:12: non-canonical import path "github.com/cmpis/project//vendor/github.com/jinzhu/inflection" (should be "github.com/cmpis/project/vendor/github.com/jinzhu/inflection")
vendor/github.com/jinzhu/gorm/model_struct.go:12: can't find import: "github.com/cmpis/project//vendor/github.com/jinzhu/inflection"

@chrisportela
Copy link

chrisportela commented Sep 15, 2016

The issue was an import with a trailing / in my own libraries. For some reason it was pointing to gorm as the source of the problem.

To find the problem in the terminal you can use grep -r "github.*/\"" . to find the problem assuming you're using mostly github.com/ imports.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 11, 2016
@griesemer
Copy link
Contributor

I suspect this is an issue with go/build or cmd/go. @rsc ?

@rsc
Copy link
Contributor

rsc commented Oct 19, 2016

The compiler error is accurate, but it's confusing because it was caused by cmd/go propagating a problem from higher in the import tree to a lower level. cmd/go should diagnose the problem earlier.

@rsc rsc changed the title cmd/compile: wrong output for a non-canonical import path cmd/go: wrong output for a non-canonical import path Oct 19, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31668 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants