-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/tools/cmd/vet: does not return the same results across workstations #12636
Comments
Are you sure that you're running the same installed version of vet? Can you give a reproducible example of code for which vet gives different output on different machines? |
Do you have GOPATH set correctly on all the machines? On 16 September 2015 at 12:30, Steve Kuznetsov [email protected]
|
@cespare I do not know why the installed version of @adg Yes, I believe we have @cespare For example. client.go returns no errors for me (on my local machine and a brand new CentOS Docker container with only golang, git and wget installed) and some other developers, but
For yet other developers. Checking the file, you can see that there are indeed unkeyed fields. We are tracking our outputs at this issue: openshift/origin#4682 |
While we are running |
@stevekuznetsov Depending on how you obtained Go 1.4.x you may be hitting the included copy of the vet tool which will override any go vet tool in GOPATH. |
@davecheney I see. On the test I did with a clean CentOS image, I got the image with
Will this method get a stale version of |
@stevekuznetsov installing go 1.4.2 gives you the version of vet that shipped with go 1.4.2. I believe that version of Go will always prefer $GOROOT/pkg/tools/linux_amd64/vet |
@davecheney Can I force it to use the version installed in |
@stevekuznetsov I think, but have not tested, you can remove the version in $GOROOT/pkg/tools/..., that should let the version in GOPATH bubble up. |
@davecheney If I delete that binary, |
@davecheney By forcing myself to use the old version of |
@davecheney @cespare Any thoughts? The older version of |
Bump. I've now checked that we are all running the same build of |
Unfortunately I don't think we are going to be able to fix this unless we can recreate it. Can you give us exact and complete instructions for how to recreate the problem? |
@ianlancetaylor I am looking right now for you guys to tell me what factors affect the operation of Instance, the invocation: $ go tool vet -shadow=false pkg/cmd/experimental/diagnostics/client.go From our repository root (referencing client.go as linked above) returns no errors on my machine, but on some others it returns the unkeyed struct literal issue on line 37. This file is 46 lines long and, while it does take some context from other files, it is the best I can do right now. Please let me know how I can make that example better for you guys. I have not been able to write a small file and get the same result, and I understand that makes it difficult because the issue with building the tree may result from having the definition of that struct in some specific file or configuration, but I do not know how to isolate that. |
any differences in $GOPATH setting among the machines?
|
@minux |
@stevekuznetsov I am not aware of anything that affects go vet operation other than the code itself, how it is invoked, the GOROOT and GOPATH environment variables, and the code that go vet is examining. |
The original issue is about the -composites warning. The -composites warning is only issued if the vet tool can determine that the composite literal is a struct. In this file, the type is from an imported package. So here is another difference that may matter (I'm not able to build your package to test this): whether the user has run "go install" for the dependent packages may change the go vet output. |
Yeah, that's probably the cause.
Try go tool vet -v and see if it outputs "could not import" warning
on machines that doesn't show the composite literal error.
See also #9439.
|
@ianlancetaylor @minux I will look into that today. Here is a list of other issues that we see intermittently between machines:
|
"returns Lock by value" will depend on installed packages if the warning is about returning the value of a type defined in a different package, where the type is a struct that contains a lock field. I have no explanation for the "no formatting directive" error, except for the rather unlikely case of writing fmt.Sprintf(otherpackage.constant). |
@ianlancetaylor As I continue to look into this, could you please clarify what you mean by
What does a failure to determine that the composite literal is a struct look like? Does |
If go vet sees T{v}, and can not determine that T is a struct type, then it will not issue a warning about unkeyed fields. It will only issue a warning about unkeyed fields if it knows that T is a struct type. If T is imported from an uninstalled package, then currently vet can not determine that T is a struct type, and it therefore will not issue a warning. |
@ianlancetaylor Do you know how well |
I have not used godeps. |
@ianlancetaylor On a fresh CentOS container, the difference between the version of |
@stevekuznetsov I think what @ianlancetaylor explained before should explain the discrepancy. go vet is a conservative tool, if it is not pretty certain about an error, it is not going to report it. It may help to understand better how go vet works: If go vet has access to all files of a package (directory) it will consider all package files (including tests). If it only has access to one file, it will only consider that one file. Keep in mind that if it sees only one file of a (multi-file) package, it obviously cannot know about the contents in those other files. If types are declared in those files and hence not available, errors that would be obvious if those types were known cannot be reported. The same is true for imports: If go vet cannot find an imported package, errors that would be obvious if those imports were available, are not reported (go vet cannot guess, it's not possible in general). Imports are only available, if the respected packages were installed in the right place. That is, in that respect, go vet operates like the compiler applied to a single package (e.g. go tool compile ). Specifically, go vet does not make an attempt to analyze the source code of imported packages - they have to be installed. The reason for this as follows: go vet makes use of the go/types package to determine type information. go/types learns about imported packages by "importing" their information from the installed packages. If they are not installed, they cannot be imported at the moment. It is possible to make an "importer" that can import from source code (open issue), but we haven't done that yet. Not knowing more about your specific setup, I suspect strongly that you get different results because your different systems have different files installed (or not installed). Which is exactly what @ianlancetaylor already suggested. I don't know of any dependency of go vet on godeps, or why it should matter. Hope that helps. I am inclined to say go vet is working as intended. |
@griesemer Thanks for the explanation. We seem to have found a |
What was the problem? Could you please give a brief explanation here
to help future readers of the this issue?
|
Absolutely. We had to tweak our
Some oddities that we were not able to find the reason for but nevertheless do not seem to be issues anymore were the The total number of |
FWIW: Until go 1.6 I really suggest people rewrite their dependencies ( |
We are attempting to integrate
go vet
's static analysis into our continuous integration pipeline for OpenShift Origin but have noticed some interesting behavior.Different developers with the same
go version
(1.4.2
) andgolang.org/x/tools/
at the sameHEAD
(c262de8 tools/cmd/vet: Sort checks list alphabetically.
) will see wildly different results from runninggo vet
. We run the tool on a subset of directories within our repository, as seen here.All of the output that we see does indeed result from defects in the code, so none of it is spurious, but some developers do not see many errors while others see ~50.
What factors affect the output of
go vet
? I think the people that have tested this have all been on different operating systems (OSX, Fedora 21,22). What can we do to ensure deterministic results?The text was updated successfully, but these errors were encountered: