Skip to content

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

Closed
@prashantv

Description

@prashantv

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions