[vala/0.44] vala: Do not allow to .resize() on arrays with fixed length
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.44] vala: Do not allow to .resize() on arrays with fixed length
- Date: Thu, 7 Nov 2019 11:20:02 +0000 (UTC)
commit 71913779edfc59526548cab320e9d702bb179b97
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 ee3f8af25..6cc135dac 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,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 37eeafb87..cbf251771 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -447,6 +447,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]