vala r1341 - in trunk: . vala



Author: juergbi
Date: Thu May  8 19:01:40 2008
New Revision: 1341
URL: http://svn.gnome.org/viewvc/vala?rev=1341&view=rev

Log:
2008-05-08  Juerg Billeter  <j bitron ch>

	* vala/valasemanticanalyzer.vala:
	* vala/valastruct.vala:

	Check number of type arguments in object creation expression,
	patch by Andreas Brauchli, fixes bug 528833


Modified:
   trunk/ChangeLog
   trunk/vala/valasemanticanalyzer.vala
   trunk/vala/valastruct.vala

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Thu May  8 19:01:40 2008
@@ -2313,9 +2313,14 @@
 		expr.static_type = expr.type_reference.copy ();
 		expr.static_type.transfers_ownership = true;
 
+		int given_num_type_args = expr.type_reference.get_type_arguments ().size;
+		int expected_num_type_args = 0;
+
 		if (type is Class) {
 			var cl = (Class) type;
 
+			expected_num_type_args = cl.get_type_parameters ().size;
+
 			if (expr.struct_creation) {
 				expr.error = true;
 				Report.error (expr.source_reference, "syntax error, use `new' to create new objects");
@@ -2344,6 +2349,8 @@
 		} else if (type is Struct) {
 			var st = (Struct) type;
 
+			expected_num_type_args = st.get_type_parameters ().size;
+
 			if (!expr.struct_creation) {
 				Report.warning (expr.source_reference, "deprecated syntax, don't use `new' to initialize structs");
 			}
@@ -2355,6 +2362,16 @@
 			}
 		}
 
+		if (expected_num_type_args > given_num_type_args) {
+			expr.error = true;
+			Report.error (expr.source_reference, "too few type arguments");
+			return;
+		} else if (expected_num_type_args < given_num_type_args) {
+			expr.error = true;
+			Report.error (expr.source_reference, "too many type arguments");
+			return;
+		}
+
 		if (expr.symbol_reference == null && expr.get_argument_list ().size != 0) {
 			expr.static_type = null;
 			expr.error = true;

Modified: trunk/vala/valastruct.vala
==============================================================================
--- trunk/vala/valastruct.vala	(original)
+++ trunk/vala/valastruct.vala	Thu May  8 19:01:40 2008
@@ -80,6 +80,15 @@
 	}
 	
 	/**
+	 * Returns a copy of the type parameter list.
+	 *
+	 * @return list of type parameters
+	 */
+	public Collection<TypeParameter> get_type_parameters () {
+		return new ReadOnlyCollection<TypeParameter> (type_parameters);
+	}
+
+	/**
 	 * Adds the specified constant as a member to this struct.
 	 *
 	 * @param c a constant



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