objects/paramspec.vala \
objects/properties.vala \
objects/property-notify.vala \
+ objects/property-read-only-auto.vala \
objects/regex.vala \
objects/signals.vala \
objects/signals-delegate.vala \
--- /dev/null
+class Foo {
+ public int read_only { get; default = 42; }
+}
+
+class Bar : Object {
+ public int read_only { get; default = 23; }
+}
+
+interface IBaz : Object {
+ public abstract int read_only { get; }
+}
+
+class Baz : Object, IBaz {
+ public int read_only { get; default = 4711; }
+}
+
+void main () {
+ var foo = new Foo ();
+ assert (foo.read_only == 42);
+
+ var bar = new Bar ();
+ assert (bar.read_only == 23);
+
+ var baz = new Baz ();
+ assert (baz.read_only == 4711);
+}
get {
if (!_field_checked) {
if (!is_abstract && source_type == SourceFileType.SOURCE) {
- bool empty_get = (get_accessor != null && get_accessor.body == null);
- bool empty_set = (set_accessor != null && set_accessor.body == null);
- if (empty_get != empty_set) {
- if (empty_get) {
- Report.error (source_reference, "Property getter must have a body");
- } else if (empty_set) {
- Report.error (source_reference, "Property setter must have a body");
- }
+ bool has_get = (get_accessor != null);
+ bool get_has_body = (has_get && get_accessor.body != null);
+ bool has_set = (set_accessor != null);
+ bool set_has_body = (has_set && set_accessor.body != null);
+ if (set_has_body && (has_get && !get_has_body)) {
+ error = true;
+ Report.error (source_reference, "Property getter must have a body");
+ }
+ if (get_has_body && (has_set && !set_has_body)) {
error = true;
+ Report.error (source_reference, "Property setter must have a body");
}
- if (empty_get && empty_set) {
+ if (!get_has_body && !set_has_body) {
/* automatic property accessor body generation */
_field = new Field ("_%s".printf (name), property_type.copy (), initializer, source_reference);
_field.access = SymbolAccessibility.PRIVATE;