[vala/staging: 1/2] vala: check a property has an accessor and/or a mutator



commit 6dfc56a54544a129e91d11202d5f1c5424d57dab
Author: Alistair Thomas <astavale yahoo co uk>
Date:   Tue Nov 8 00:36:58 2016 +0000

    vala: check a property has an accessor and/or a mutator
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=773956

 tests/Makefile.am              |    2 ++
 tests/objects/bug773956-1.test |   10 ++++++++++
 tests/objects/bug773956-2.test |   10 ++++++++++
 vala/valaproperty.vala         |    6 ++++++
 4 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cfda178..d3c709a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -190,6 +190,8 @@ TESTS = \
        objects/bug760031.test \
        objects/bug767092.test \
        objects/bug768823.test \
+       objects/bug773956-1.test \
+       objects/bug773956-2.test \
        objects/bug615830-1.test \
        objects/bug615830-2.test \
        errors/errors.vala \
diff --git a/tests/objects/bug773956-1.test b/tests/objects/bug773956-1.test
new file mode 100644
index 0000000..94b1616
--- /dev/null
+++ b/tests/objects/bug773956-1.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+class Foo : Object {
+       public int bar {}
+}
+
+void main () {
+       new Foo ();
+}
+
diff --git a/tests/objects/bug773956-2.test b/tests/objects/bug773956-2.test
new file mode 100644
index 0000000..a0457af
--- /dev/null
+++ b/tests/objects/bug773956-2.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+class Foo : Object {
+       private int bar {}
+}
+
+void main () {
+       new Foo ();
+}
+
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 9da3508..19aad24 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -395,6 +395,12 @@ public class Vala.Property : Symbol, Lockable {
 
                property_type.check (context);
 
+               if (get_accessor == null && set_accessor == null) {
+                       error = true;
+                       Report.error (source_reference, "Property `%s' must have a `get' accessor and/or a 
`set' mutator".printf (get_full_name ()));
+                       return false;
+               }
+
                if (get_accessor != null) {
                        get_accessor.check (context);
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]