Skip to content

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

Closed
@prashantv

Description

@prashantv

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions