]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Parameter following params-array parameter is not allowed
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 26 May 2021 07:02:52 +0000 (09:02 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 26 May 2021 10:18:47 +0000 (12:18 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1183

tests/Makefile.am
tests/methods/params-array-preceding.test [new file with mode: 0644]
vala/valamethod.vala

index cfe4adbb4e78e68f504998bf44144548cf614b46..3e754e58e2bbbf440500c74e8da7d5ca1c091426 100644 (file)
@@ -229,6 +229,7 @@ TESTS = \
        methods/nowrapper-no-vfunc.test \
        methods/params-array.vala \
        methods/params-array-abstract.test \
+       methods/params-array-preceding.test \
        methods/params-array-with-throws.vala \
        methods/print-attribute.vala \
        methods/print-attribute-invalid.test \
diff --git a/tests/methods/params-array-preceding.test b/tests/methods/params-array-preceding.test
new file mode 100644 (file)
index 0000000..0e57bf1
--- /dev/null
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo (params string[] strv, int i) {
+}
+
+void main () {
+}
index 427a379804ee8e0208609eb30eabbf391df8ad51..daef9789f6b21e0cb5d3bfb13f978a3692b6a182 100644 (file)
@@ -848,6 +848,7 @@ public class Vala.Method : Subroutine, Callable {
                }
 
                var optional_param = false;
+               var params_array_param = false;
                foreach (Parameter param in parameters) {
                        if (!param.check (context)) {
                                error = true;
@@ -872,6 +873,11 @@ public class Vala.Method : Subroutine, Callable {
                                optional_param = true;
                        }
 
+                       if (params_array_param) {
+                               Report.error (param.source_reference, "parameter follows params-array parameter");
+                       } else if (param.params_array) {
+                               params_array_param = true;
+                       }
                        // Add local variable to provide access to params arrays which will be constructed out of the given va-args
                        if (param.params_array && body != null) {
                                if (params_array_var != null) {