Go "X redeclared in this block / other declaration of X" in CI
Go forbids two declarations of the same identifier in one scope. The compiler reports both the redeclaration and the location of the original "other declaration".
What this error means
Compilation fails with "X redeclared in this block" and a follow-up line "other declaration of X" pointing at the first definition.
go build
./parse.go:18:6: parse redeclared in this block
./parse.go:9:6: other declaration of parseCommon causes
The same name defined twice in a package
Two functions, types, or package-level vars share a name, often after copy-paste or a merge.
A variable shadowed and redeclared in the same block
A second := or var reuses a name already declared in the same lexical block.
How to fix it
Rename or remove the duplicate
- Open both locations the compiler prints.
- Decide which definition is correct and rename or delete the other.
- For a merge artifact, remove the accidental copy.
parse.go
// keep one declaration; rename or delete the duplicate
func parseConfig() (*Config, error) { ... }Reuse the existing variable instead of redeclaring
Within a block, assign with = to the existing variable rather than re-declaring it with := or var.
How to prevent it
- Build the whole package in CI so duplicate names are caught.
- Resolve merge conflicts carefully; duplicates often arrive that way.
- Use distinct, intent-revealing names to avoid collisions.
Related guides
Go "missing function body" in CIFix Go "missing function body" in CI - a function is declared with no body and no assembly stub, usually from…
Go "non-declaration statement outside function body" in CIFix Go "syntax error: non-declaration statement outside function body" in CI - executable code was placed at…
Go "t.Method undefined (type T has no field or method Method)" in CIFix Go "t.Method undefined (type T has no field or method Method)" in CI - a method or field is called on a v…