Skip to content

A static property over a same-named static field (limit / Limit) emits a duplicate name in C, Go and Rust (compile error) and overwrites the field in Python #444

Closed

Description

@matt-edmondson

What's wrong

A colliding getter is only renamed with a get prefix when the target sets MemberNamesMustDiffer:

  • Coder/Languages/StandardLanguageGenerator.cs:1148: protected virtual bool MemberNamesMustDiffer => false;
  • StandardLanguageGenerator.cs:1186: HashSet<string> taken = MemberNamesMustDiffer ? NamesOf(classDecl.Members) : [];
  • StandardLanguageGenerator.cs:1290: the getter is renamed only if (MemberNamesMustDiffer && taken.Contains(getterName)).

Only CppGenerator.cs:150 overrides it to true, which was the fix for #140 and covered the C++ instance case. Other targets share one namespace between static fields and the lowered static getter, and never check for a clash:

  • C and Go move static fields to file or package scope.
  • Rust puts associated consts in the same impl as the getter fn.
  • Python's static path, PythonGenerator.GenerateStaticAccessors (PythonGenerator.cs:205-218), names the @staticmethod with GetterName(Snake) and never checks either.

Reproduction

ClassDeclaration("Gauge") with:

  • FieldDeclaration("limit", "int") { IsStatic = true, IsConstant = true, InitialValue = 10 }
  • PropertyDeclaration { Name = "Limit", HasGetter = true, IsStatic = true } with getter return 10

A non-const total / Total pair behaves the same way.

Target Output Result
C static const int Gauge_limit = 10; and int Gauge_limit(void) gcc: 'Gauge_limit' redeclared as different kind of symbol
Go const GaugeLimit int = 10 and func GaugeLimit() go vet: GaugeLimit redeclared in this block
Rust pub const limit: i32 = 10; and pub fn limit() in the same impl rustc E0592: duplicate definitions with name limit
Python limit: int = 10 then def limit() Compiles, but after import Gauge.limit is a function and the field's value is lost
C++ get_limit() Correct

A field with a PascalCase property over it is the most common C# property pattern, so this hits ordinary models when they are targeted at C, Go, Rust or Python.

Suggested fix / acceptance criteria

  • When a static or constant field and a property's getter would get the same spelled name in a target's shared namespace, rename the getter with the get prefix C++ already uses (get_limit / GetLimit). This covers C, Go, Rust and Python's static accessor path.
  • Leave non-colliding names unchanged.
  • Add a test per target that compiles the snippet above with gcc -std=c11, go vet and rustc, and a Python test that Gauge.limit == 10 after import.

Related: #140 / PR #221 (the C++ instance-member version of this), and #141 (self-references in accessor bodies, a separate issue).

Activity

  1. added
    bug
    on Nov 3, 2026
  2. matt-edmondson commented on Nov 3, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions