[vala/staging] valaparser: Don't allow to declare array parameters with "type array[]"



commit 7426438896bacd661004702ab4dd430f8d56e956
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Oct 11 17:27:01 2016 +0200

    valaparser: Don't allow to declare array parameters with "type array[]"
    
    It is required to have a fixed length like "type array[3]".
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/163

 tests/Makefile.am                | 1 +
 tests/basic-types/bug641308.test | 7 +++++++
 vala/valaparser.vala             | 7 ++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 64a6e6805..0f0c8f007 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,7 @@ TESTS = \
        basic-types/bug604589.test \
        basic-types/bug622178.vala \
        basic-types/bug632322.vala \
+       basic-types/bug641308.test \
        basic-types/bug643612.vala \
        basic-types/bug644046.vala \
        basic-types/bug647222.vala \
diff --git a/tests/basic-types/bug641308.test b/tests/basic-types/bug641308.test
new file mode 100644
index 000000000..b530077f9
--- /dev/null
+++ b/tests/basic-types/bug641308.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo (int i[]) {
+}
+
+void main () {
+}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index f110452b4..01ad01d29 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -3286,7 +3286,12 @@ public class Vala.Parser : CodeVisitor {
                }
                string id = parse_identifier ();
 
-               type = parse_inline_array_type (type);
+               var array_type = parse_inline_array_type (type);
+               if (!(type is ArrayType) && (array_type is ArrayType) && !((ArrayType) 
array_type).fixed_length) {
+                       throw new ParseError.SYNTAX ("invalid array parameter declaration");
+               } else {
+                       type = array_type;
+               }
 
                var param = new Parameter (id, type, get_src (begin));
                set_attributes (param, attrs);


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