Go "mixed named and unnamed parameters" - Fix Signatures in CI
By Kaveh Alemi·Latchkey
A function signature mixes named and unnamed entries in one parameter or result list. Go requires every entry in a list to be all named or all unnamed, so the mixed form is a syntax error.
What this error means
The build fails to parse with syntax error: mixed named and unnamed parameters (or ... function results), pointing at the signature. Nothing past it compiles because the declaration is malformed.
go build output
./api.go:12:6: syntax error: mixed named and unnamed parameters
# from: func Do(ctx context.Context, string) error // 'string' is unnamed
Diagnose it: toolchain, tags, or platform?
Go build failures that only appear in CI usually come from a different toolchain version, different build tags, or cross-compilation defaults that differ from your machine.
Terminal
go version
go env GOOS GOARCH CGO_ENABLED GOFLAGS GOTOOLCHAIN
# build exactly what CI builds, verbosely
go build -v ./... 2>&1 | tail -40
# CGO is the usual difference: on by default locally, often off in a slim CI image
CGO_ENABLED=0 go build ./...
Common causes
Some parameters named, others not
Writing func f(a int, string) names a but leaves the second parameter unnamed. Within one list Go demands all-named or all-unnamed.
Mixed named and unnamed return values
A result list like (n int, error) mixes a named result with an unnamed one, which is the same forbidden mix on the results side.
How to fix it
Make the list consistently named
Give every parameter (or result) a name when any of them are named.
Go
func Do(ctx context.Context, name string) error { ... } // all named
func Split(s string) (head string, tail string) { ... } // all named results
Or make it consistently unnamed
If you do not need names, drop them from all entries in the list.
Go
func Do(context.Context, string) error { ... } // all unnamed
How to prevent it
Keep each parameter and result list all-named or all-unnamed.
Run gofmt/go vet so signature syntax errors surface immediately.
Prefer named results only when they aid readability, applied to every entry.
Frequently asked questions
What causes Go "mixed named and unnamed parameters"?
There are 2 common causes: some parameters named, others not and mixed named and unnamed return values. Writing func f(a int, string) names a but leaves the second parameter unnamed.
How do I fix Go "mixed named and unnamed parameters"?
There are 2 fixes depending on which cause you have: make the list consistently named and or make it consistently unnamed. Work through them in order, since the first is the most common.
What does Go "mixed named and unnamed parameters" actually mean?
The build fails to parse with syntax error: mixed named and unnamed parameters (or ...
How do I stop Go "mixed named and unnamed parameters" happening again?
Keep each parameter and result list all-named or all-unnamed. The prevention section lists 3 changes that keep it from recurring.