Repository navigation
Description
What's wrong
C++ has no properties, so StandardLanguageGenerator.Separate lowers a property with accessor bodies into a getter/setter pair. The getter is named property.GetterName(MemberNaming), and C++ sets MemberNaming to NamingStyle.Snake, so a property Count gets the getter count().
The most common way to write a property with bodies is over a private camelCase field of the same name: field count, property Count. In C++ the getter then takes exactly the name of the field it wraps, and a data member and a member function can't share a name.
- Getter/setter separation:
Coder/Coder/Languages/StandardLanguageGenerator.cs
Lines 368 to 420 in 8753490
private IEnumerable<AstNode> Separate(PropertyDeclaration property) { if (property.IsAutomatic) { // The one thing the field form cannot carry: a property may be readable and not // writable, and a field is neither or both. Said in the field's own documentation // rather than in a note beside it, so it travels with the declaration to wherever this // target puts it. IEnumerable<string> documentation = property.CanWrite ? property.Documentation : [.. property.Documentation, $"{property.Name} is read-only, which a field is not."]; yield return new FieldDeclaration(property.Name ?? "value", property.Type) { Visibility = property.Visibility, IsStatic = property.IsStatic, Documentation = [.. documentation], Annotations = [.. property.Annotations.Select(annotation => annotation.Clone())], }; yield break; } if (property.CanRead) { FunctionDeclaration getter = new(property.GetterName(MemberNaming)) { ReturnType = property.Type, Visibility = property.Visibility, IsStatic = property.IsStatic, IsReadOnly = true, Documentation = [.. property.Documentation], Annotations = [.. property.Annotations.Select(annotation => annotation.Clone())], Body = [.. property.GetterBody.Select(statement => statement.Clone())], }; yield return getter; } if (property.CanWrite) { FunctionDeclaration setter = new(property.SetterName(MemberNaming)) { ReturnType = new TypeReference("void"), Visibility = property.Visibility, IsStatic = property.IsStatic, Body = [.. property.SetterBody.Select(statement => statement.Clone())], }; setter.Parameters.Add(new Parameter("value") { Type = property.Type ?? new TypeReference("object") }); yield return setter; } } - Getter name:
Coder/Coder/Ast/PropertyDeclaration.cs
Line 141 in 8753490
public string GetterName(NamingStyle style) => NameStyles.Spell(Name ?? "value", style); - C++ member naming:
Coder/Coder/Languages/CppGenerator.cs
Lines 96 to 100 in 8753490
/// <inheritdoc/> /// <remarks> /// The standard library spells an invented accessor <c>set_value</c>, and that is the convention a reader of any C++ header already has. /// </remarks> protected override NamingStyle MemberNaming => NamingStyle.Snake; - C++ separating class members:
Coder/Coder/Languages/CppGenerator.cs
Line 338 in 8753490
classDecl = Separated(classDecl);
Repro (against 8753490)
var cls = new ClassDeclaration("Counter");
cls.Members.Add(new FieldDeclaration("count", new TypeReference("int")) { Visibility = Visibility.Private, InitialValue = new LiteralExpression<int>(0) });
var prop = new PropertyDeclaration("Count", new TypeReference("int")) { Visibility = Visibility.Public, HasSetter = true };
prop.GetterBody.Add(new ReturnStatement(new VariableReference("count")));
prop.SetterBody.Add(new AssignmentStatement(new VariableReference("count"), new VariableReference("value")));
cls.Members.Add(prop);
new CppGenerator().Generate(cls);emits
class Counter
{
private:
int count = 0;
public:
int count() const
{
return count;
}
void set_count(int value) ...and g++ -std=c++20 -fsyntax-only reports:
error: 'int Counter::count() const' conflicts with a previous declaration
note: previous declaration 'int Counter::count'
The same AST generates valid code for every other target. C# and Python keep Count and count apart, Rust allows a field and a method with the same name, Go writes Count(), and C prefixes the name as Counter_count. Only C++ fails.
Why it matters
A class written in the ordinary C# style can't be emitted as C++. C++ is also the target that downstream consumers, such as ktsu.Semantics' C++ projection, generate headers with.
Suggested fix / acceptance criteria
- When lowering a property, check the generated getter and setter names against the class's other member names. On a clash, choose a spelling that doesn't collide (for example
get_count()) and apply it deterministically. - Add a
CppGeneratedSourceCompilesTestscase: fieldcountplus a propertyCountwith bodies compiles, and a driver can call the getter and setter. - Pin the chosen spelling in
CppGeneratorTests.
Activity
matt-edmondson commentedon Oct 5, 2026
Triage
count, propertyCountwith bodies) emits C++ that does not compile. C++ is the target downstream header generation uses. It affects only C++.StandardLanguageGenerator.Separate,PropertyDeclaration.GetterName,CppGeneratormember namingget_count()). Add the compile test inCppGeneratedSourceCompilesTestsand pin the spelling inCppGeneratorTests.Generated by Claude Code