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



commit d843effcae8e957b0b4619899bd6050ccb48fcf7
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]".
    
    https://bugzilla.gnome.org/show_bug.cgi?id=641308

 tests/Makefile.am                |    1 +
 tests/basic-types/bug641308.test |    7 +++++++
 vala/valaparser.vala             |    7 ++++++-
 3 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a01cd5b..cf536c2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@ TESTS = \
        basic-types/bug596637.vala \
        basic-types/bug596785.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 0000000..b530077
--- /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 02677c6..bd9d255 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -3272,7 +3272,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]