[vala/staging: 2/2] vala: Multi-dimensional params-array not allowed




commit d07258653abe9ea6ac26ffd1655b3f70290a91ba
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Sep 22 13:44:35 2021 +0200

    vala: Multi-dimensional params-array not allowed
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1230

 tests/Makefile.am                                 |  1 +
 tests/methods/params-array-multi-dimensional.test |  7 +++++++
 vala/valaparameter.vala                           | 14 ++++++++++----
 3 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ed1ef5980..f77a696f5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -232,6 +232,7 @@ TESTS = \
        methods/nowrapper-no-vfunc.test \
        methods/params-array.vala \
        methods/params-array-abstract.test \
+       methods/params-array-multi-dimensional.test \
        methods/params-array-preceding.test \
        methods/params-array-with-throws.vala \
        methods/print-attribute.vala \
diff --git a/tests/methods/params-array-multi-dimensional.test 
b/tests/methods/params-array-multi-dimensional.test
new file mode 100644
index 000000000..d66d5abaf
--- /dev/null
+++ b/tests/methods/params-array-multi-dimensional.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo (params string[,] strvv) {
+}
+
+void main () {
+}
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index 41a59da61..7bbb2cedb 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -152,10 +152,16 @@ public class Vala.Parameter : Variable {
                if (!ellipsis) {
                        variable_type.check (context);
 
-                       if (params_array && !(variable_type is ArrayType)) {
-                               error = true;
-                               Report.error (source_reference, "parameter array expected");
-                               return false;
+                       if (params_array) {
+                               if (!(variable_type is ArrayType)) {
+                                       error = true;
+                                       Report.error (source_reference, "parameter array expected");
+                                       return false;
+                               } else if (((ArrayType) variable_type).rank != 1) {
+                                       error = true;
+                                       Report.error (source_reference, "multi-dimensional parameter array 
not allowed");
+                                       return false;
+                               }
                        }
 
                        if (has_attribute_argument ("CCode", "scope") && variable_type is DelegateType) {


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