From: Juerg Billeter Date: Mon, 4 Feb 2008 23:41:00 +0000 (+0000) Subject: improve error reporting for properties, fixes bug 514326 X-Git-Tag: VALA_0_1_7~124 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5c1d1469c7e5e90c9300a818f323e9bf952f1fa9;p=thirdparty%2Fvala.git improve error reporting for properties, fixes bug 514326 2008-02-05 Juerg Billeter * vala/valaclass.vala: improve error reporting for properties, fixes bug 514326 * tests/classes-properties.vala: fix test case svn path=/trunk/; revision=967 --- diff --git a/ChangeLog b/ChangeLog index 121fd31d7..5ba7aa015 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-02-05 Jürg Billeter + + * vala/valaclass.vala: improve error reporting for properties, + fixes bug 514326 + + * tests/classes-properties.vala: fix test case + 2008-02-05 Jürg Billeter * gobject/valaccodeassignmentbinding.vala, diff --git a/tests/classes-properties.vala b/tests/classes-properties.vala index 4dff4ff99..922e37a7e 100644 --- a/tests/classes-properties.vala +++ b/tests/classes-properties.vala @@ -7,7 +7,7 @@ public class Sample : Object { private string _name; public string name { - get; + get { return _name; } set { _name = value; diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 033eebd78..587e0087c 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -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); + } } }