]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Check number of type arguments in object creation expression, patch by
authorJuerg Billeter <j@bitron.ch>
Thu, 8 May 2008 19:01:40 +0000 (19:01 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 8 May 2008 19:01:40 +0000 (19:01 +0000)
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

svn path=/trunk/; revision=1341

ChangeLog
vala/valasemanticanalyzer.vala
vala/valastruct.vala

index cfee63700ee1e7daf04a8aa3514c581a027b4aac..cdccbaae9300cfcbe0bda3aca021a7f517b36de0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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
index 91f1cf509ff9838fa5a2188b40c83e6868503e16..e594fda557dc569afb492edd97f759bc57aba817 100644 (file)
@@ -2313,9 +2313,14 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                } 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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        }
                }
 
+               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;
index 8b13fb9e69bad5393e93b78bf1be69b6f6b6bb38..bd97bd06382c66754de1b5e5632f3ebda65e9c6e 100644 (file)
@@ -79,6 +79,15 @@ public class Vala.Struct : Typesymbol {
                scope.add (p.name, p);
        }
        
+       /**
+        * 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.
         *