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 reports unknown identifier in example code #113

Closed
xthezealot opened this issue Mar 31, 2016 · 24 comments
Closed

go_vet reports unknown identifier in example code #113

xthezealot opened this issue Mar 31, 2016 · 24 comments
Assignees
Labels

Comments

@xthezealot
Copy link

xthezealot commented Mar 31, 2016

For example, the github.com/gowww/compress package.

The package name compress is suffixed with _test inside the example_test.go file.
That's maybe why this go vet doesn't recognize the identifier reference.

But it should.
And locally, my go vet github.com/gowww/compress returns no error.

@shawnps
Copy link
Contributor

shawnps commented Mar 31, 2016

@ArthurWhite that is strange behavior indeed.

i can't reproduce it on my local, but i see it failing on the go report card server. i opened a ticket with gometalinter, will see what the author says:

alecthomas/gometalinter#108

@shawnps
Copy link
Contributor

shawnps commented Mar 31, 2016

Looks like it's not gometalinter but rather something strange going on with vet on the server...I'll try to investigate further soon

@shawnps
Copy link
Contributor

shawnps commented Apr 29, 2016

Weird, go vet passes on command line on my local, but fails with the same errors when running Go Report Card locally.

@hectorj
Copy link

hectorj commented May 17, 2016

What go versions are you guys using?

I have a similar problem in one of my projects: it works with Go 1.5.X, but fails with Go 1.6.X

Edit:

Also see openshift/origin#4682 and golang/go#12636

@xthezealot
Copy link
Author

xthezealot commented May 17, 2016

Personally, I have the 1.6.2 darwin/amd64 installed with Homebrew.

What is even weirder is that Go Report Card returns a 100% success for another package (github.com/gowww/log) which follows exactly the same "template".

@xthezealot
Copy link
Author

I just pushed a new commit and Go Report Card fails for this package too. 💣

example_test.go
Previously e31412b
Now a2e97ea

@db47h
Copy link

db47h commented Jan 24, 2017

Same for this package: https://goreportcard.com/report/github.com/db47h/cache

I use go 1.7 and go-tip as test code is not compatible with go <1.7,

@korthaj
Copy link

korthaj commented Jun 18, 2017

Maybe this is a caching issue? In my case, I got the false positive

radix/example_test.go
Line 8: error: ExampleSortSlice refers to unknown identifier: SortSlice (vet)

Perhaps go vet is looking at the new version of the file example_test.go and an older cached version of the file that actually contains SortSlice. I did, in fact, use goreportcard earlier, when the new function and the new test didn't yet exist.

@shawnps
Copy link
Contributor

shawnps commented Jun 18, 2017

@korthaj unfortunately I don't believe it's a caching issue but rather an issue with go tool vet itself. I just ran it manually against your repo and I get the error:

$ go tool vet *.go
example_test.go:8: ExampleSortSlice refers to unknown identifier: SortSlice

gometalinter uses go tool vet rather than go vet, I believe for historical reasons. Someone brought up a similar issue here:

alecthomas/gometalinter#218

If I can find a way to have gometalinter use go vet instead of go tool vet, it might be fixable.

@xthezealot
Copy link
Author

xthezealot commented Jun 18, 2017

If I can find a way to have gometalinter use go vet instead of go tool vet, it might be fixable.

At first glance, just calling go vet instead of gometalinter at check/go_vet.go:21 should do the fix.
'Doesn't work like this?

@arsham
Copy link

arsham commented Sep 21, 2017

I'm experiencing the same problem here
from this report. The identifier is defined and on local version it reports no issues.

@GoLangsam
Copy link

Same experience with my new repo github.com/GoLangsam/template using unnamed import aka import . "html/template" (as does standard html/template/template_test.go).

Local use of go vet and go tool vet remains silent.

Local use of gometalinter gives same "noise"!
Local use of goreportcard (under Windows - mind You :-) with latest gometalinter gives same "noise"!

After patching check/go_vet.go to:

return GoTool(g.Dir, g.Filenames, []string{"go", "tool", "vet"})

things are fine :-)

(except for small and unrelated Windows-issues - and that's a separate story!)

@shawnps shawnps self-assigned this Sep 25, 2017
@shawnps
Copy link
Contributor

shawnps commented Sep 25, 2017

I will take a look at this soon.

@GoLangsam
Copy link

Looking @ alecthomas/gometalinter#218 I feel that they'r pushing this off to the go tool chain. Thus, there is no hope for any quick solution soon.

Having browsed cmd/go/main.go and friends such as pkg.go I understand the trouble of the go team in supporting the variety of usages of their tools.

I also understand and experience: the best (if I may say so) way to point to packages is inside a workspace ($GOPATH set) and via import-path-of-package\....

Looking @ Your implementation, I see:

  • You supply individual filenames ... (to be discussed separtely)
  • nowhere do not (attempt to) touch $GOPATH

Thus: I just set my $GOPATH the _repo - and: All is fine and copathetic :-) :-) :-)

So, I'd humbly like to recommend: Stay far away from non-standard usage of package pointers when using go tools!

(Note: There's even a myriad of issues, blogs etc. around explaining very good reasone as of why some usage styles have to behave in ways unexpected to the naive and innocent user.)

@GoLangsam
Copy link

GoLangsam commented Sep 26, 2017

@shawnps Having found a.m. evidence, I'll have to read and think a little more in order to come up with a feasible and robust solution which suits Your fine product.

@GoLangsam
Copy link

@shawnps @hermanschaaf

here we go - Sorry for keeping You waiting :-)

@stevenh
Copy link

stevenh commented Nov 3, 2017

This is still an issue, I've raised it against go vet:
golang/go#22530

@stevenh
Copy link

stevenh commented Nov 7, 2017

As suggested by Russ Cox if the calls to go tool vet are replaced with calls to go vet examples pass.

@breml
Copy link

breml commented May 28, 2018

I have a similar problem with my package logstash-config.

Locally go vet ., go tool vet . as well as gometalinter . do not return an error. I use go version go1.10.1 linux/amd64. On goreportcard.com the following error is shown (https://goreportcard.com/report/github.com/breml/logstash-config):

logstash-config/logstash_config_test.go
Line 12: error: ExampleParseReader refers to unknown identifier: ParseReader (vet)

The ParseReader function is defined in logstash_config.go, which is a generated file and therefore has the comment // Code generated by pigeon; DO NOT EDIT., which instructs the go tools to not perform linting and vetting on this file (see golang/go#13560 (comment) for details).

@rameshvk
Copy link

I hit this regularly when working with examples (with a _test package name). Gometalinter will pass locally but goreportcard reports these false warnings. In most cases, I am able to change the example to use the same package name but sometimes that causes import cycles....

mrinalwadhwa added a commit to build-trust/did that referenced this issue Nov 10, 2018
1. make calls to String() explicit
2. move the examples to the did package to address this bug
in gometalinter gojp/goreportcard#113
@mrinalwadhwa
Copy link

Have the same problem in this report https://goreportcard.com/report/github.com/ockam-network/did

Locally go vet github.com/ockam-network/did returns no errors.

@blockloop
Copy link

blockloop commented Apr 9, 2019

I'm having the same issue on my repo.

I was able to reproduce by running go vet <file> against only the example_test file rather than against the whole repo.

λ go vet example_scanner_test.go
# command-line-arguments_test
./example_scanner_test.go:33:1: ExampleRow refers to unknown identifier: Row
./example_scanner_test.go:55:1: ExampleRow_scalar refers to unknown identifier: Row
./example_scanner_test.go:74:1: ExampleRows refers to unknown identifier: Rows
./example_scanner_test.go:96:1: ExampleRows_primitive refers to unknown identifier: Rows
- master
λ go vet github.com/blockloop/scan
- master
λ

@ljmsc
Copy link

ljmsc commented Apr 17, 2019

hi,
i had the same issue. Please note the naming convention described here:
https://golang.org/pkg/testing/#hdr-Examples

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity.

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