summaryrefslogtreecommitdiff
path: root/vala/valaproperty.vala
diff options
context:
space:
mode:
authorAlistair Thomas <astavale@yahoo.co.uk>2018-06-25 18:57:08 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2018-07-04 17:43:09 +0200
commitcbb92150d54e66b1bd84775d58d9f4b8a305967e (patch)
treebbaf2ba697dc53004b57f71be025c6abed680d01 /vala/valaproperty.vala
parent12a560a22cbda229f490787b9a5d17aaff0bca82 (diff)
downloadvala-cbb92150d54e66b1bd84775d58d9f4b8a305967e.tar.gz
vala: Allow read-only properties
See https://gitlab.gnome.org/GNOME/vala/merge_requests/10
Diffstat (limited to 'vala/valaproperty.vala')
-rw-r--r--vala/valaproperty.vala20
1 files changed, 11 insertions, 9 deletions
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 6e5ae6973..aa899f636 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -103,17 +103,19 @@ public class Vala.Property : Symbol, Lockable {
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;