[vala/0.36: 29/212] codegen: NoAccessorMethod attribute is allowed for gobject-properties only



commit b14c36a67b6d277953e15da4104a2fdf2a558566
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed May 17 11:37:56 2017 +0200

    codegen: NoAccessorMethod attribute is allowed for gobject-properties only

 tests/Makefile.am                       |    1 +
 tests/annotations/noaccessormethod.test |    9 +++++++++
 vala/valaclass.vala                     |    5 +++++
 3 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b199632..2968238 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -289,6 +289,7 @@ TESTS = \
        gir/array-fixed-length.test \
        annotations/deprecated.vala \
        annotations/description.vala \
+       annotations/noaccessormethod.test \
        $(NULL)
 
 NON_NULL_TESTS = \
diff --git a/tests/annotations/noaccessormethod.test b/tests/annotations/noaccessormethod.test
new file mode 100644
index 0000000..235bb78
--- /dev/null
+++ b/tests/annotations/noaccessormethod.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+public class Foo {
+       [NoAccessorMethod]
+       public string baz { get; set; }
+}
+
+void main () {
+}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index 211c321..fdac092 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -674,6 +674,11 @@ public class Vala.Class : ObjectTypeSymbol {
                }
                
                foreach (Property prop in properties) {
+                       if (prop.get_attribute ("NoAccessorMethod") != null && !is_subtype_of 
(context.analyzer.object_type)) {
+                               error = true;
+                               Report.error (prop.source_reference, "NoAccessorMethod is only allowed for 
properties in classes derived from GLib.Object");
+                               return false;
+                       }
                        prop.check (context);
                }
                


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