go vet complains about undefined methods, even though go test succeeds

Created on 4 Aug 2018  ·  10Comments  ·  Source: golang/go

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)
FrozenDueToAge

Most helpful comment

I see this issue for go 1.12.

go version
go version go1.12 darwin/amd64

All 10 comments

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.

I see this issue for go 1.12.

go version
go version go1.12 darwin/amd64

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

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

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

Any update on this. This just happened to me. I am using go1.11.5 darwin/amd64. GOVET fails with undefined: 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

This is still happening to me on 1.12.5, created a new issue https://github.com/golang/go/issues/32408

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.

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

@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$
Was this page helpful?
0 / 5 - 0 ratings