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

cmd/vet: Re-typed slice expects explicit keys, but only for fields inside of a struct #15408

prashantv opened this issue Apr 22, 2016 · 3 comments


Copy link

@prashantv prashantv commented Apr 22, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
go version go1.6.2 darwin/amd64
  1. What operating system and processor architecture are you using (go env)?
    As above, darwin + amd64. Running OSX 10.11.4
  2. What did you do?
    Ran go vet for the following code:

Basically has a foo.go with:

package vetrepro

type Container struct {
    List StringList

// StringList is a list of strings
type StringList []string

And a foo_test.go:

package vetrepro_test

import ""

// This causes a failure
var _ = &vetrepro.Container{
    List: vetrepro.StringList{"hello", "world", "asdasd", "asdasd"},

// This works even though it's essentially the same.
var list = vetrepro.StringList{"hello", "world", "asdasd", "asdasd"}
var _ = &vetrepro.Container{
    List: list,
  1. What did you expect to see?
    No errors from go vet for both places were I create vetrepro.StringList.
  2. What did you see instead?
    An error for the first case (where the StringList is created inline when setting the List field), but no error for the second case, where the StringList is created separately from the Container.
$ go vet .
foo_test.go:7: vetrepro.StringList composite literal uses unkeyed fields

If the issue is that vet needs the installed packages, I'd expect that both cases would be affected.
go install does fix this issue, but I'm not clear why the error is inconsistent between the 2 cases.

@ianlancetaylor ianlancetaylor modified the milestones: unp, Unplanned Apr 22, 2016
Copy link

@byron-janrain byron-janrain commented Apr 22, 2016

This was also a surprise for us, breaking our build when we upgraded to 1.6.

Copy link

@extemporalgenome extemporalgenome commented Apr 22, 2016

This may be related to #9171

Copy link

@gopherbot gopherbot commented Apr 23, 2016

CL mentions this issue.

@gopherbot gopherbot closed this in 22db3c5 Apr 28, 2016
flawedmatrix added a commit to cloudfoundry-attic/tcp-emitter that referenced this issue Aug 8, 2016
In the move to go1.6, using a declared type as a slice shows up as an
error in go vet:
tcp_routes.TCPRoutes composite literal uses unkeyed fields

This error will be fixed in go1.7:
@golang golang locked and limited conversation to collaborators Apr 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants