[vala/0.40] 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.40] vala: Do not allow to .resize() on arrays with fixed length
- Date: Sun, 10 Nov 2019 17:06:17 +0000 (UTC)
commit 6d7dcb7f21a34fc30e92ed7141f7a8fd11c518b3
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 98384bd4f..9cb8ffb45 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -68,6 +68,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/slice-invalid-start.test \
arrays/slice-invalid-stop.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 ef81c3cde..94da85103 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -450,6 +450,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]