Skip to content
Latchkey

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 fields

Common 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

  1. 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

  1. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →