vala r967 - in trunk: . tests vala



Author: juergbi
Date: Mon Feb  4 23:41:00 2008
New Revision: 967
URL: http://svn.gnome.org/viewvc/vala?rev=967&view=rev

Log:
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


Modified:
   trunk/ChangeLog
   trunk/tests/classes-properties.vala
   trunk/vala/valaclass.vala

Modified: trunk/tests/classes-properties.vala
==============================================================================
--- trunk/tests/classes-properties.vala	(original)
+++ trunk/tests/classes-properties.vala	Mon Feb  4 23:41:00 2008
@@ -7,7 +7,7 @@
 
 	private string _name;
 	public string name {
-		get;
+		get { return _name; }
 
 		set {
 			_name = value;

Modified: trunk/vala/valaclass.vala
==============================================================================
--- trunk/vala/valaclass.vala	(original)
+++ trunk/vala/valaclass.vala	Mon Feb  4 23:41:00 2008
@@ -229,13 +229,27 @@
 		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);
+			}
 		}
 	}
 	



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