GALA-E0030 — Struct field redeclared

What it means. A struct declares two fields with the same name. Both struct syntaxes are covered:


Code that triggers it

package main

struct Point(X int, X int)

func main() {
    val p = Point(1, 2)
    Println(p.X)
}

Compiler message

error[GALA-E0030]: field "X" already declared in struct "Point"
  --> main.gala:3:21
  |
3 | struct Point(X int, X int)
  |                     ^ rename or remove the duplicate field
  |
  = hint: rename or remove the duplicate field

The caret points at the second occurrence of the name. The block form reports identically:

error[GALA-E0030]: field "x" already declared in struct "Point"
  --> main.gala:5:9
  |
5 |     val x int
  |         ^ rename or remove the duplicate field
  |
  = hint: rename or remove the duplicate field

How to fix it

Rename the duplicate, or delete it if it was a copy-paste artefact:

package main

struct Point(X int, Y int)

func main() {
    val p = Point(1, 2)
    Println(s"${p.X}, ${p.Y}")
}

If you wanted several values under one conceptual name, hold a collection instead of repeating the field:

import . "martianoff/gala/collection_immutable"

struct Path(Points Array[int])

Why the rule exists

The duplicate was doubly damaging. The field-type map kept only the later type, so the earlier field’s type was lost; and the ordered field-name list contained the name twice, which the generator emitted verbatim — producing Go with a duplicated struct field that could not compile. Because the resulting failure surfaced in generated code, it pointed at a line the author never wrote. Rejecting in the analyzer keeps the error on the declaration.

Scope. Fields within one struct declaration. A field name that collides with a type name in the same package is GALA-E0016; duplicate sealed-variant case names are GALA-E0031.


GALA-E0011 types · GALA-E0012 methods · GALA-E0027 functions · GALA-E0028 type aliases · GALA-E0029 interface method specs · GALA-E0030 struct fields · GALA-E0031 sealed cases