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

net.LookupIP fails #41

Closed
rogpeppe opened this issue Jun 20, 2016 · 7 comments
Closed

net.LookupIP fails #41

rogpeppe opened this issue Jun 20, 2016 · 7 comments
Labels

Comments

@rogpeppe
Copy link
Owner

Trying to find the definition of LookupIP in the following code fails:

package main
import "net"

var x = net.LookupIP

func main() {
}

Looking at the debug output, it's probably something to do with build tags:

2016/06/20 10:36:56 exprType tuple:false pkg: *ast.SelectorExpr net.LookupIP [
2016/06/20 10:36:56 exprType tuple:false pkg: *ast.Ident net [
2016/06/20 10:36:56 exprType tuple:false pkg: *ast.ImportSpec "net" [
2016/06/20 10:36:56 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2016/06/20 10:36:56 ] -> 0xc42010d950, Type{package "" *ast.ImportSpec "net"}
2016/06/20 10:36:56 member Type{package "" *ast.ImportSpec "net"} 'LookupIP' {
2016/06/20 10:36:56     /home/rog/go/src/net/interface_bsdvar.go:12:2: cannot find identifier for package "golang.org/x/net/route": no buildable Go source files in /home/rog/go/src/vendor/golang.org/x/net/route
2016/06/20 10:36:56 } -> <nil>
2016/06/20 10:36:56 ] -> 0x0, Type{bad "" <nil> }
2016/06/20 10:36:56 exprType tuple:false pkg: *ast.SelectorExpr net.LookupIP [
2016/06/20 10:36:56 exprType tuple:false pkg: *ast.Ident net [
2016/06/20 10:36:56 exprType tuple:false pkg: *ast.ImportSpec "net" [
2016/06/20 10:36:56 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2016/06/20 10:36:56 ] -> 0xc42010d950, Type{package "" *ast.ImportSpec "net"}
2016/06/20 10:36:56 member Type{package "" *ast.ImportSpec "net"} 'LookupIP' {
2016/06/20 10:36:56     /home/rog/go/src/net/interface_bsdvar.go:12:2: cannot find identifier for package "golang.org/x/net/route": no buildable Go source files in /home/rog/go/src/vendor/golang.org/x/net/route
2016/06/20 10:36:56 } -> <nil>
2016/06/20 10:36:56 ] -> 0x0, Type{bad "" <nil> }
@rogpeppe rogpeppe added the bug label Jun 20, 2016
@walktall
Copy link

walktall commented Jul 5, 2016

godef -debug -f /usr/local/Cellar/go/1.6.2/libexec/src/log/syslog/syslog.go -o 3403
2016/07/05 13:57:07 exprType tuple:false pkg: *ast.SelectorExpr net.Dial [
2016/07/05 13:57:07 exprType tuple:false pkg: *ast.Ident net [
2016/07/05 13:57:07 exprType tuple:false pkg: *ast.ImportSpec "net" [
2016/07/05 13:57:07 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2016/07/05 13:57:07 ] -> 0xc8201de690, Type{package "" *ast.ImportSpec "net"}
2016/07/05 13:57:07 member Type{package "" *ast.ImportSpec "net"} 'Dial' {
2016/07/05 13:57:07     /usr/local/Cellar/go/1.6.2/libexec/src/net/cgo_android.go:10:8: cannot find identifier for package "C": cannot find package "C" in any of:
    /usr/local/Cellar/go/1.6.2/libexec/src/vendor/C (vendor tree)
    /usr/local/Cellar/go/1.6.2/libexec/src/C (from $GOROOT)
    /Users/Zhiheng/Workspace/go/src/C (from $GOPATH)
2016/07/05 13:57:07 } -> <nil>
2016/07/05 13:57:07 ] -> 0x0, Type{bad "" <nil> }
2016/07/05 13:57:07 exprType tuple:false pkg: *ast.SelectorExpr net.Dial [
2016/07/05 13:57:07 exprType tuple:false pkg: *ast.Ident net [
2016/07/05 13:57:07 exprType tuple:false pkg: *ast.ImportSpec "net" [
2016/07/05 13:57:07 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2016/07/05 13:57:07 ] -> 0xc8201de690, Type{package "" *ast.ImportSpec "net"}
2016/07/05 13:57:07 member Type{package "" *ast.ImportSpec "net"} 'Dial' {
2016/07/05 13:57:07     /usr/local/Cellar/go/1.6.2/libexec/src/net/cgo_android.go:10:8: cannot find identifier for package "C": cannot find package "C" in any of:
    /usr/local/Cellar/go/1.6.2/libexec/src/vendor/C (vendor tree)
    /usr/local/Cellar/go/1.6.2/libexec/src/C (from $GOROOT)
    /Users/Zhiheng/Workspace/go/src/C (from $GOPATH)
2016/07/05 13:57:07 } -> <nil>
2016/07/05 13:57:07 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for net.Dial

Is this one related here?

@hotpxl
Copy link

hotpxl commented Jul 27, 2016

I'm having a related issue on Arch Linux with go1.6.3 linux/amd64

When I try godef --debug -f abc.go net.DialTimeout, it returns

2016/07/27 20:45:52 exprType tuple:false pkg: *ast.SelectorExpr net.DialTimeout [
2016/07/27 20:45:52 exprType tuple:false pkg: *ast.Ident net [
2016/07/27 20:45:52 exprType tuple:false pkg: *ast.ImportSpec "net" [
2016/07/27 20:45:52 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2016/07/27 20:45:52 ] -> 0xc820143a40, Type{package "" *ast.ImportSpec "net"}
2016/07/27 20:45:52 member Type{package "" *ast.ImportSpec "net"} 'DialTimeout' {
2016/07/27 20:45:52     /usr/lib/go/src/net/conf_netcgo.go:14:8: cannot find identifier for package "C": cannot find package "C" in any of:
        /usr/lib/go/src/vendor/C (vendor tree)
        /usr/lib/go/src/C (from $GOROOT)
        /home/hotpxl/go/src/C (from $GOPATH)
2016/07/27 20:45:52 } -> <nil>
2016/07/27 20:45:52 ] -> 0x0, Type{bad "" <nil> }
2016/07/27 20:45:52 exprType tuple:false pkg: *ast.SelectorExpr net.DialTimeout [
2016/07/27 20:45:52 exprType tuple:false pkg: *ast.Ident net [
2016/07/27 20:45:52 exprType tuple:false pkg: *ast.ImportSpec "net" [
2016/07/27 20:45:52 ] -> 0x0, Type{package "" *ast.ImportSpec "net"}
2016/07/27 20:45:52 ] -> 0xc820143a40, Type{package "" *ast.ImportSpec "net"}
2016/07/27 20:45:52 member Type{package "" *ast.ImportSpec "net"} 'DialTimeout' {
2016/07/27 20:45:52     /usr/lib/go/src/net/conf_netcgo.go:14:8: cannot find identifier for package "C": cannot find package "C" in any of:
        /usr/lib/go/src/vendor/C (vendor tree)
        /usr/lib/go/src/C (from $GOROOT)
        /home/hotpxl/go/src/C (from $GOPATH)
2016/07/27 20:45:52 } -> <nil>
2016/07/27 20:45:52 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for net.DialTimeout

Looks like it's having problems importing cgo

@muirdm
Copy link

muirdm commented Oct 3, 2016

#44 fixed this issue for me.

@sky126
Copy link

sky126 commented Oct 11, 2016

github.com\rogpeppe\godef\go\parser\parser.go

// p.error(path.Pos(), fmt.Sprintf("cannot find identifier for package %q: %v", litToString(path), err))

fixed this

@rongyi
Copy link

rongyi commented Apr 27, 2017

master branch still has this problem?

@bboreham
Copy link

It seems to me that there is a mismatch between two implementations of "exclude files that are not for the current architecture".

One is in godef/go/types/goodarch.go:goodOSArch(), which decides purely on the file name.
The other is in go/build/build.go:shouldBuild() via Context.match() which looks at // +build lines.

So for the example at the top the former decides /home/rog/go/src/net/interface_bsdvar.go is ok, and the latter decides there are no files to parse in /home/rog/go/src/vendor/golang.org/x/net/route, because they are all excluded by +build directives.

Given that build.Default.Import() returns a set of Go files and ignored Go files, could we not use them instead of the isGoFile logic?

@rogpeppe
Copy link
Owner Author

Fixed by #62

YMhao added a commit to YMhao/godef that referenced this issue Nov 30, 2018
YMhao added a commit to YMhao/godef that referenced this issue Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants