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 vet complains about undefined methods, even though go test succeeds #26797

Closed
prashantv opened this issue Aug 3, 2018 · 10 comments
Closed

Comments

@prashantv
Copy link
Contributor

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

1.10.3

$ go version
go version go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

Yes, 1.10.3 is the latest release.

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

linux, amd64
> go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/prashant/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

What did you do?

Made go vet complain about an undefined method, even though go test works fine.

Repro in: https://github.com/prashantv/govet-bug

/home/prashant/go/src/github.com/prashantv/govet-bug
$ ls
registry

/home/prashant/go/src/github.com/prashantv/govet-bug
$ go test ./registry
ok      github.com/prashantv/govet-bug/registry (cached)

/home/prashant/go/src/github.com/prashantv/govet-bug
$ go vet ./registry
# github.com/prashantv/govet-bug/registry_test
registry/registry_test.go:11:3: r.HandleGroup undefined (type *registrytest.Registry has no field or method HandleGroup)

What makes this case tricky is that:
registry_utils_test.go is a test file that exports an unexported method
registry_test.go is trying to call the exported method through an external type that embeds the original Registry.

If I import the registry package, then the error goes away.

What did you expect to see?

go vet to not complain about a missing field/method, since go test passes, and the method should be promoted from registry.Registry to registrytest.Registry.

What did you see instead?

The error as reported earlier,

registry/registry_test.go:11:3: r.HandleGroup undefined (type *registrytest.Registry has no field or method HandleGroup)

In a larger codebase internally, go vet crashed,

Made go vet crash.
# [...]/registry_test
<unknown line number>: internal compiler error: no function definition for [0xc420c60360] FUNC-method(*registry.Registry) func(http.ResponseWriter, *http.Request)
@ianlancetaylor
Copy link
Contributor

Thanks for reporting the bug. I can reproduce this with 1.10 but not with 1.11beta3. So I assume this is fixed in the upcoming 1.11 release. This isn't something we will fix on the release branch, so closing this issue.

carmenlau added a commit to carmenlau/skygear-server that referenced this issue Oct 18, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
carmenlau added a commit to carmenlau/skygear-server that referenced this issue Oct 18, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
Steven-Chan pushed a commit to Steven-Chan/skygear-server that referenced this issue Oct 18, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
Steven-Chan pushed a commit to Steven-Chan/skygear-server that referenced this issue Oct 18, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
Steven-Chan pushed a commit to Steven-Chan/skygear-server that referenced this issue Oct 19, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
Steven-Chan pushed a commit to Steven-Chan/skygear-server that referenced this issue Oct 19, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
Steven-Chan pushed a commit to Steven-Chan/skygear-server that referenced this issue Oct 23, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
Steven-Chan pushed a commit to Steven-Chan/skygear-server that referenced this issue Oct 23, 2018
There is bug in go that even tests pass, vet complains about undefined methods. And they only fixed it in go 1.11.
golang/go#26797
@ktian94
Copy link

ktian94 commented Mar 5, 2019

I see this issue for go 1.12.

go version
go version go1.12 darwin/amd64

@xuchen81
Copy link

Anyone know how to fix this, I'm on go1.12.1 darwin/amd64, see the same issue.

@amoore877
Copy link

given the recent reports starting on March 5th of this being re-introduced in 1.12, this issue should be re-opened, or a new one created.
This is still an on-going problem

@rshirani
Copy link

rshirani commented Apr 30, 2019

Any update on this. This just happened to me. I am using go1.11.5 darwin/amd64. GOVET fails with undefined: <struct_name> when calling an struct from the same package that is in a different file.
Which version do you recommend to be on?

@amoore877
Copy link

Any update on this. This just happened to me. I am using go1.11.5 darwin/amd64. GOVET fails with undefined: <struct_name> when calling an struct from the same package that is in a different file.
Which version do you recommend to be on?

for me, I had to update separate tooling my organization uses, which itself depends on go. So I am assuming in my case that there was some non-obvious conflict between the go version on my system and the go version my tooling was using.
while it would be a little hard to believe that this is the case for everyone still having this issue, if you are using some separate tooling (rather than calling go vet directly) try updating that tool

@cosmin-mogos
Copy link

This is still happening to me on 1.12.5, created a new issue #32408

@tx0c
Copy link

tx0c commented Jul 1, 2019

This isn't something we will fix on the release branch, so closing this issue.

why was this closed, till today I can reproduce with go1.12.6, why go vet complain undefined ... something; but it's clearly all well defined, because go test can pass.

@ianlancetaylor
Copy link
Contributor

Reopening to see if it still occurs. For people reporting it: does it occur with the original test case?

@ianlancetaylor ianlancetaylor reopened this Jul 1, 2019
@bcmills
Copy link
Contributor

bcmills commented Jul 1, 2019

@tx0c, I can't reproduce this issue with go1.12.6 using the steps as originally posted. If you are seeing an issue with similar symptoms, the underlying cause may or may not be the same. Please file a new issue with concrete steps (and source files) to reproduce it.

$ go1.12.6 get -d github.com/prashantv/govet-bug/registry

$ cd $GOPATH/src/github.com/prashantv/govet-bug

_gopath/src/github.com/prashantv/govet-bug$ go1.12.6 test ./registry
ok      github.com/prashantv/govet-bug/registry 0.020s

_gopath/src/github.com/prashantv/govet-bug$ go1.12.6 vet ./registry

_gopath/src/github.com/prashantv/govet-bug$

@bcmills bcmills closed this as completed Jul 1, 2019
@golang golang locked and limited conversation to collaborators Jun 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants