-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: flags composite literals of slice types from other packages as using unkeyed fields #11394
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
Comments
I also ran into this today. Here is a repro as small as I can easily make it (it requires an imported package):
To be clear, this seems like a totally bogus warning. |
The vet check needs to know about types. cc @josharian @robpike |
I believe that this is yet another case of using gcimporter when what we really want to do is to load from source. Note that if you put @cespare's example into GOPATH and use an absolute import rather than a relative import, vet does the right thing. This is a perennial problem at this point. The correct, deep fix is probably to stabilize the go/loader API (cc @alandonovan), put go/loader in the stdlib, and use it in cmd/vet. The superficial fix is to not complain when we are missing type information, which seems like a better default anyway. I can send a CL for that if @robpike agrees. |
I don't think this is true. I originally found this problem with real packages and only used a relative path for my repro. Here's another GOPATH-based repro:
|
@cespare if you |
@josharian ah, it does not. |
Yep. :) Loading from source would fix that. |
Josh: Maybe open an issue for goimporter and link it to here? |
This appears to have been fixed in Go 1.7. It's extra-fixed now because in Go 1.10 go vet makes sure that vet has full type information 100% of the time. |
My Go version is
go version go1.4.2 linux/amd64
.I've got the following situation:
When running
go vet
inunkeyed-example/slice
, I get no error.When running
go vet
inunkeyed-example/ex1
, I get the following output:main.go:11: slice.Int composite literal uses unkeyed fields
. In this case, I expectgo vet
to treat the literalslice.Int{ value }
the same asInt{ value }
, and thus, not to indicate an error.When running
go vet
inunkeyed-example/ex2
, I again get no error. This is meant as validation thatgo vet
indeed expects an explicit key and will show no error when provided with one (in this case, the key is an index to the slice).My general expectation here is that
go vet
would behave consistently, no matter whether a literal refers to a slice type within the same package or to a slice type from another package.The text was updated successfully, but these errors were encountered: