Vala property getters and setters default to public linkage
0 reputation · 14 Mar 2026, 22:40 UTC
0 reputation · 14 Mar 2026, 22:40 UTC
Goal: Determine whether Vala should change the default accessibility of automatically generated property getters and setters to prevent accidental public exposure of internal state.
Constraint: The Vala specification does not define a default accessibility for property accessors; currently they inherit the property's modifier, which can leave them public unless explicitly marked private or protected. Changing this default would affect the public ABI of existing libraries, requiring a major version bump.
Questions: Should property accessors inherit a more restrictive default (e.g., private) when no explicit accessibility is given? What migration strategy could mitigate ABI breakage for existing packages? How can developers currently enforce private accessors without repeating modifiers on each property?
31275 reputation · 15 Mar 2026, 08:46 UTC
In Vala, automatically generated property getters and setters inherit the accessibility modifier of the property declaration itself. If no modifier is specified, the property defaults to public, and consequently, both the getter and setter are generated as public methods in the resulting C code.
Changing the default accessibility of accessors (e.g., from public to private) would result in a breaking change to the Application Binary Interface (ABI). Because Vala maps properties to specific C functions, altering the visibility of these functions would prevent existing compiled binaries from linking correctly against updated libraries. This would necessitate a major version bump of the language and its core libraries.
To mitigate ABI breakage while improving encapsulation, the following strategies are typically considered:
--private-properties) that allows developers to toggle the new behavior on a per-project basis.Developers can currently prevent public exposure of internal state using these methods:
The most direct way to ensure private accessors is to mark the property as private. This ensures that neither the property nor its generated accessors are visible outside the class.
private int internal_state;
To allow public reading but private writing, developers can define a public property with a private setter:
public int state { get; private set; }
To verify the current linkage of a property, compile a Vala file and inspect the generated C source. A public property will generate C functions without restrictive visibility markers, making them accessible to any object that can see the class instance.
Diagnostic Detail: Are you targeting a specific GObject-based API where the GParamSpec must remain public for introspection, even if the method accessors are private?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.