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



commit 536ee9fb64d45132a66ccb9637f649e6258a42c0
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 fbc25c3bc..24f060f2a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -231,6 +231,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]