[vala/staging] vala: Do not allow to .resize() on arrays with fixed length



commit 2e62cf3188b953498559d2cf96045a43bb0f98c8
Author: Florian Brosch <flo brosch gmail com>
Date:   Wed Sep 17 14:49:00 2014 +0200

    vala: Do not allow to .resize() on arrays with fixed length

 tests/Makefile.am                             | 1 +
 tests/arrays/fixed-length-resize-invalid.test | 6 ++++++
 vala/valamemberaccess.vala                    | 8 ++++++++
 3 files changed, 15 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 775110cbb..4d2be1385 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -76,6 +76,7 @@ TESTS = \
        arrays/field-global-length-cname.vala \
        arrays/fixed-length-concat-invalid.test \
        arrays/fixed-length-non-const.test \
+       arrays/fixed-length-resize-invalid.test \
        arrays/struct-field-length-cname.vala \
        arrays/incompatible-integer-elements.test \
        arrays/slice-invalid-start.test \
diff --git a/tests/arrays/fixed-length-resize-invalid.test b/tests/arrays/fixed-length-resize-invalid.test
new file mode 100644
index 000000000..5386fd76d
--- /dev/null
+++ b/tests/arrays/fixed-length-resize-invalid.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+       int foo[2] = { 23, 42 };
+       foo.resize (3);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 927e57531..9316e5644 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -452,6 +452,14 @@ public class Vala.MemberAccess : Expression {
                                        may_access_klass_members = true;
                                }
                        }
+
+                       if (symbol_reference is ArrayResizeMethod && inner.value_type is ArrayType) {
+                               unowned ArrayType? value_array_type = inner.value_type as ArrayType;
+                               if (value_array_type != null && value_array_type.inline_allocated) {
+                                       Report.error (source_reference, "`resize' is not supported for arrays 
with fixed length");
+                                       error = true;
+                               }
+                       }
                }
 
                // enum-type inference


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