]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
improve error reporting for properties, fixes bug 514326
authorJuerg Billeter <j@bitron.ch>
Mon, 4 Feb 2008 23:41:00 +0000 (23:41 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Mon, 4 Feb 2008 23:41:00 +0000 (23:41 +0000)
2008-02-05  Juerg Billeter  <j@bitron.ch>

* vala/valaclass.vala: improve error reporting for properties,
  fixes bug 514326

* tests/classes-properties.vala: fix test case

svn path=/trunk/; revision=967

ChangeLog
tests/classes-properties.vala
vala/valaclass.vala

index 121fd31d707607ee29fac8fe075463f576ba6f72..5ba7aa015031401f0f786851dc964e81e29ba3d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-05  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaclass.vala: improve error reporting for properties,
+         fixes bug 514326
+
+       * tests/classes-properties.vala: fix test case
+
 2008-02-05  Jürg Billeter  <j@bitron.ch>
 
        * gobject/valaccodeassignmentbinding.vala,
index 4dff4ff9950045eaa835ad6c9b98bb59762b498e..922e37a7ea41306e90de74465d8f3bd08aeb5d77 100644 (file)
@@ -7,7 +7,7 @@ public class Sample : Object {
 
        private string _name;
        public string name {
-               get;
+               get { return _name; }
 
                set {
                        _name = value;
index 033eebd785c68b10bfa04b611c7e210f9ff39a12..587e0087c65eb5eff944b90042711a8607f4705f 100644 (file)
@@ -229,13 +229,27 @@ public class Vala.Class : Typesymbol {
                prop.this_parameter = new FormalParameter ("this", new ClassType (this));
                prop.scope.add (prop.this_parameter.name, prop.this_parameter);
                
-               if (!no_field && prop.set_accessor != null && prop.set_accessor.body == null &&
-                   source_reference != null && !source_reference.file.pkg) {
-                       /* automatic property accessor body generation */
-                       var field_type = prop.type_reference.copy ();
-                       var f = new Field ("_%s".printf (prop.name), field_type, null, prop.source_reference);
-                       f.access = SymbolAccessibility.PRIVATE;
-                       add_field (f);
+               if (!no_field && source_reference != null && !source_reference.file.pkg) {
+                       bool empty_get = (prop.get_accessor != null && prop.get_accessor.body == null);
+                       bool empty_set = (prop.set_accessor != null && prop.set_accessor.body == null);
+
+                       if (empty_get != empty_set) {
+                               if (empty_get) {
+                                       Report.error (prop.source_reference, "property getter must have a body");
+                               } else if (empty_set) {
+                                       Report.error (prop.source_reference, "property setter must have a body");
+                               }
+                               prop.error = true;
+                               return;
+                       }
+
+                       if (empty_get && empty_set) {
+                               /* automatic property accessor body generation */
+                               var field_type = prop.type_reference.copy ();
+                               var f = new Field ("_%s".printf (prop.name), field_type, null, prop.source_reference);
+                               f.access = SymbolAccessibility.PRIVATE;
+                               add_field (f);
+                       }
                }
        }