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

Closed
prashantv opened this issue Apr 22, 2016 · 3 comments

Comments

Projects
None yet
5 participants
@prashantv
Copy link
Contributor

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:
    https://github.com/prashantv/vetrepro

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 "github.com/prashantv/vetrepro"

// 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

@byron-janrain

This comment has been minimized.

Copy link

commented Apr 22, 2016

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

@extemporalgenome

This comment has been minimized.

Copy link

commented Apr 22, 2016

This may be related to #9171

@gopherbot

This comment has been minimized.

Copy link

commented Apr 23, 2016

CL https://golang.org/cl/22318 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

Temporary fix to quell go vet error
In the move to go1.6, using a declared type as a slice shows up as an
error in go vet:
```
routing_table/schema/endpoint/endpoint_utils_test.go:130:
tcp_routes.TCPRoutes composite literal uses unkeyed fields
```

This error will be fixed in go1.7:
golang/go#15408

@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.
You can’t perform that action at this time.