Skip to content

Write static properties that compile in C++ and are reachable from the class in Python [patch] - #209

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/180-static-property
Oct 12, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/180-static-property

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #180

What changed

C++: StandardLanguageGenerator.Separated lowered every property getter with IsReadOnly = true, including static ones. CppGenerator then wrote static int limit() const, and g++ rejects that with "static member function cannot have cv-qualifier".

  • The getter is now IsReadOnly = !property.IsStatic.
  • CppGenerator also writes const only when the function is not static. That covers a hand-built static, read-only FunctionDeclaration too.
  • The other generators that use Separated (C, Go, Rust) give a static function no receiver, so IsReadOnly on a static getter never reached their output. They are unchanged.

Python: GeneratePropertyDeclaration never read IsStatic, so a static property with bodies became an instance @property. Read from the class, that answers the property object, not the value. It is now written as two @staticmethod functions, limit() and set_limit(value). This is the lowering C, Rust and Go already use, and both functions can be called on the class. An automatic static property is unchanged: it is still a class attribute.

Tests

  • CppGeneratedSourceCompilesTests.AStaticPropertyGetterCompiles: Counter.Limit (static, getter returns 10) generates static int limit() with no const. A driver calling Counter::limit() compiles with -Wall -Wextra -pedantic -Werror.
  • PythonGeneratedSourceImportsTests.StaticProperty_IsReachableFromTheClass: runs the generated module and checks that Counter.limit() == 10, that it also works on an instance, and that Counter.set_limit(3) can be called.

With the generator changes reverted, both tests fail. With them, the full suite passes (1117/1117).

🤖 Generated with Claude Code

https://claude.ai/code/session_01EP9qqymiBp8RePCRRnDfQk


Generated by Claude Code

…e class in Python [patch]

A static property's getter was lowered with IsReadOnly set, so C++ wrote
`static int limit() const`, which g++ rejects. The getter is now read-only
only when it is an instance member, and CppGenerator never writes `const`
on a static member function.

Python wrote a static property with bodies as an instance `@property`, so
reading it from the class answered the property object. It is now written
as `@staticmethod` getter and setter functions, `limit()` and
`set_limit(value)`, as C, Rust and Go already lower it.

Fixes #180

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EP9qqymiBp8RePCRRnDfQk
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit ebb0eec into main Oct 12, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/180-static-property branch October 12, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static property getter emits static int limit() const in C++ (does not compile), and Python ignores IsStatic on properties

2 participants