Go vet "composite literal uses unkeyed fields" - Fix in CI
The composites vet check flags struct literals from other packages that set fields positionally instead of by name. Unkeyed literals silently break when the upstream struct adds or reorders a field, so vet (and golangci-lint’s govet) fail the build on them.
What this error means
A go vet ./... step fails with <Type> composite literal uses unkeyed fields, naming a struct from an imported package. The code compiles; vet is warning that the positional literal is fragile.
./main.go:14:10: github.com/org/lib.Options composite literal
uses unkeyed fieldsCommon causes
A positional struct literal from another package
Writing lib.Options{"a", 5, true} instead of lib.Options{Name: "a", Size: 5, On: true} depends on the field order, which the upstream package can change.
A generated or copied literal that drifted
A literal copied from an older struct definition, or generated against a previous version, no longer matches and vet catches the fragility.
How to fix it
Key the fields by name
Name each field so the literal is robust to reordering and additions.
opts := lib.Options{
Name: "a",
Size: 5,
On: true,
}Run vet/golangci-lint to find every occurrence
go vet ./...
# or via golangci-lint's govet
golangci-lint run --enable govet ./...How to prevent it
- Always use keyed fields for struct literals from other packages.
- Keep
go vet/govet in CI so unkeyed literals fail PRs. - Regenerate code against the current struct definitions.