Skip to content

vala: allow read only properties

Al Thomas requested to merge astavale/vala:readonly-property into master

Genie has the readonly keyword for read only properties:

class Test
  prop readonly name:string = "packages"

this is the equivalent of the Vala code:

class Test {
  public string name { get; default = "packages"; }
}

With d2d2e183 the Genie code no longer compiles. Instead Vala comes back with a compile time error "error: Property getter must have a body". This is because vala/valaproperty.vala does not allow automatic backing fields for read only properties. I can't think why that is not allowed so this merge request fixes that. It works for both Vala and Genie. It also allows set only properties to have automatic backing fields as well. Although I'm not sure sink properties should be encouraged - use a method instead.

The merge request is based on the following analysis:

Vala Example `get` Present `get` Body `set` Present `set` Body Automatic Backing Field
`{}` error - see 6dfc56a5
`{get;}`
`{get {return true;}}`
`{set;}`
`{set {_data = true;}}`
`{get;set;}`
`{get{return true;}set;}` error - set needs body
`{get;set{_date = true;}}` error - get needs body
`{get{return true;}set{_data=true;}}`
Edited by Al Thomas

Merge request reports