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

go/types: config.Check complains "can't find import" for vendored packages if they haven't been installed #14496

Closed
metakeule opened this issue Feb 24, 2016 · 4 comments
Assignees
Milestone

Comments

@metakeule
Copy link

@metakeule metakeule commented Feb 24, 2016

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

$ go version
go version go1.6 linux/amd64

2 What operating system and processor architecture are you using?

$ cat /etc/issue
Ubuntu 15.10 \n \l

$ lscpu
Architecture:          x86_64
...

3 What did you do?

$ tree $GOPATH/src
├── a
│   ├── a.go
│   └── vendor
│       └── b
│           └── b.go
└── build
    └── main.go

$ cat $GOPATH/src/build/main.go
package main

    import (
        "go/ast"
        "go/build"
        "go/importer"
        "go/parser"
        "go/token"
        "go/types"
        "os"
        "path"
    )

    func panicOnErr(err error) {
        if err != nil {
            panic(err.Error())
        }
    }

    func main() {
        gopath := os.Getenv("GOPATH")   
        dir := path.Join(gopath, "src", "a")

        //  println("dir: " + dir)
        fset := token.NewFileSet()
        buildPkg, err := build.ImportDir(dir, build.ImportMode(0))

        panicOnErr(err)

        astFiles := []*ast.File{}

        for _, filename := range buildPkg.GoFiles {
            file, err := parser.ParseFile(fset, path.Join(dir, filename), nil, parser.AllErrors)
            panicOnErr(err)
            astFiles = append(astFiles, file)
        }

        for _, filename := range buildPkg.CgoFiles {
            file, err := parser.ParseFile(fset, path.Join(dir, filename), nil, parser.AllErrors)
            panicOnErr(err)
            astFiles = append(astFiles, file)
        }

        typesInfo := &types.Info{
            Types: make(map[ast.Expr]types.TypeAndValue),
            Defs:  make(map[*ast.Ident]types.Object),
            Uses:  make(map[*ast.Ident]types.Object),
        }

        var conf types.Config
        conf.Importer = importer.Default()
        conf.IgnoreFuncBodies = true
        typesPkg, err := conf.Check(buildPkg.Name, fset, astFiles, typesInfo)

        panicOnErr(err)

        _ = typesPkg
    }
$ cat $GOPATH/src/a/a.go
    package a

    import "b"

    var foo = b.Foo
$ cat $GOPATH/src/a/vendor/b/b.go
    package b

    var Foo = "bar"

4 What did you expect to see?

Nothing (that's OK)

$ go run build/main.go

5 What did you see instead?

$ go env && go version && go run $GOPATH/src/build/main.go 
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/benny/Entwicklung/testdebug/gopath"
GORACE=""
GOROOT="/home/benny/bin/go"
GOTOOLDIR="/home/benny/bin/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
go version go1.6 linux/amd64
panic: a/a.go:3:8: could not import b (can't find import: a/vendor/b)

goroutine 1 [running]:
panic(0x653760, 0xc82000ade0)
    go/src/runtime/panic.go:464 +0x3e6
main.panicOnErr(0x7fb0a76aac58, 0xc82000fe00)
    build/main.go:16 +0x7e
main.main()
    build/main.go:56 +0x8bd
exit status 2

Further information

When installing the vendor package

$ go install $GOPATH/src/a/vendor/b 

before running

$ go run $GOPATH/src/build/main.go

It runs fine as expected. After removing the build

$ rm $GOPATH/pkg/linux_amd64/a/vendor/b.a

It complains again

$ go run $GOPATH/src/build/main.go
panic: a/a.go:3:8: could not import b (can't find import: a/vendor/b)

goroutine 1 [running]:
panic(0x653760, 0xc82000ade0)
    go/src/runtime/panic.go:464 +0x3e6
main.panicOnErr(0x7fb0a76aac58, 0xc82000fe00)
    build/main.go:16 +0x7e
main.main()
    build/main.go:56 +0x8bd
exit status 2

Probably related to #14215

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Feb 25, 2016
@griesemer
Copy link
Contributor

@griesemer griesemer commented Feb 26, 2016

Duplicate of #11415.

Loading

@Tectract
Copy link

@Tectract Tectract commented Jan 20, 2017

build liteide tools ...
../../../../.go/src/github.com/visualfc/gotools/types/types.go:12:2: cannot find package "go/importer" in any of:

../../../../.go/src/github.com/visualfc/gotools/astview/astview.go:12:2: cannot find package "go/types" in any of:

have no idea what to do. Help?

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jan 20, 2017

@Tectract This is issue is not the place for asking questions. If you have a new issue, please file one with a clear description of what's wrong. If you have a general question, please consult with one of the Go forums. Thanks.

Loading

@Tectract
Copy link

@Tectract Tectract commented Jan 20, 2017

hey I thought it was related. Problem solved by manually installing latest version of go.

Loading

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

Successfully merging a pull request may close this issue.

None yet
5 participants