Go vet "composite literal uses unkeyed fields" - Fix in CI
go vet warns when a struct literal from another package omits field names. Positional literals break silently when the struct gains or reorders fields, so vet flags them - and CI that gates on vet fails.
What this error means
A vet or test run fails with composite literal uses unkeyed fields. It commonly appears for literals of types from imported packages, especially after a dependency added a field.
go
./main.go:18:14: github.com/foo/bar.Config composite literal uses unkeyed fieldsCommon causes
Positional literal of an imported struct
A struct from another package is initialized by position, so any field change silently shifts values.
vet gated in CI
go test runs vet by default, so the warning becomes a hard failure in the pipeline.
How to fix it
Use keyed fields
- Rewrite the literal to name each field so it is robust to struct changes.
Go
cfg := bar.Config{
Host: "localhost",
Port: 8080,
}Run vet locally before pushing
- Run go vet to catch unkeyed literals before CI does.
Terminal
go vet ./...How to prevent it
- Always key struct literals of imported types.
- Run
go vet ./...before pushing. - Let your editor or gofmt enforce keyed fields.
Related guides
Go "cannot use X (variable of type A) as B value" - Fix in CIFix Go "cannot use X (variable of type A) as B value in argument" in CI - a value of the wrong type was passe…
Go "too many errors" during build - Fix in CIFix Go "too many errors" in CI - the compiler stopped printing after a cap, hiding most failures. Fix the fir…
Go "build constraints exclude all Go files" - Fix in CIFix Go "build constraints exclude all Go files in package" in CI - every file is filtered out by build tags o…