[vala/0.54] vala: Parameter following ellipsis parameter is not allowed



commit ec462d4e4b5e1246234a481032bae5a01a267a5b
Author: wxx <769218589 qq com>
Date:   Thu Oct 14 17:48:00 2021 +0800

    vala: Parameter following ellipsis parameter is not allowed
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1237

 tests/Makefile.am                     | 1 +
 tests/methods/ellipsis-preceding.test | 7 +++++++
 vala/valamethod.vala                  | 8 ++++++++
 3 files changed, 16 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d42298f6f..f35f5aeca 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -169,6 +169,7 @@ TESTS = \
        methods/lambda.vala \
        methods/closures.vala \
        methods/contains.vala \
+       methods/ellipsis-preceding.test \
        methods/extern.vala \
        methods/iterator.vala \
        methods/parameter-fixed-array-initializer.vala \
diff --git a/tests/methods/ellipsis-preceding.test b/tests/methods/ellipsis-preceding.test
new file mode 100644
index 000000000..b687a339c
--- /dev/null
+++ b/tests/methods/ellipsis-preceding.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo (int i, ..., int j) {
+}
+
+void main () {
+}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 9ad3c2059..f03df3a4c 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -849,6 +849,7 @@ public class Vala.Method : Subroutine, Callable {
 
                var optional_param = false;
                var params_array_param = false;
+               var ellipsis_param = false;
                foreach (Parameter param in parameters) {
                        if (!param.check (context)) {
                                error = true;
@@ -873,11 +874,18 @@ public class Vala.Method : Subroutine, Callable {
                                optional_param = true;
                        }
 
+                       // Disallow parameter after params array or ellipsis
                        if (params_array_param) {
                                Report.error (param.source_reference, "parameter follows params-array 
parameter");
                        } else if (param.params_array) {
                                params_array_param = true;
                        }
+                       if (ellipsis_param) {
+                               Report.error (param.source_reference, "parameter follows ellipsis parameter");
+                       } else if (param.ellipsis) {
+                               ellipsis_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) {


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