+2008-05-08 Jürg 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
+
2008-05-08 Jaap A. Haitsma <jaap@haitsma.org>
reviewed by: Jürg Billeter
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");
} 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");
}
}
}
+ 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;
}
/**
+ * 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