]> 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>
Fri, 4 Jun 2021 07:19:51 +0000 (09:19 +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 0cf57444b301b9cbc7bf5472656d6ca8a35f37bb..abf9372e926765139e69779d312a30de32557b90 100644 (file)
@@ -228,6 +228,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 0bed502b9fbd180a6e9d5ec50c99fd2e479826f1..9c34c7ad04302193337b16c29c11cc222c278bef 100644 (file)
@@ -841,6 +841,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;
@@ -865,6 +866,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) {