[vala/0.44] vala: Do not allow to change .length of 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 change .length of arrays with fixed length
- Date: Thu, 7 Nov 2019 11:20:07 +0000 (UTC)
commit 1046e3be73a85de301b41f7f977c02d5c2409ae7
Author: Florian Brosch <flo brosch gmail com>
Date: Wed Sep 17 14:45:52 2014 +0200
vala: Do not allow to change .length of arrays with fixed length
This would result in invalid C code.
tests/arrays/fixed-length-read-only-length.test | 6 ++++++
vala/valaassignment.vala | 4 ++++
2 files changed, 10 insertions(+)
---
diff --git a/tests/arrays/fixed-length-read-only-length.test b/tests/arrays/fixed-length-read-only-length.test
new file mode 100644
index 000000000..b53eb112a
--- /dev/null
+++ b/tests/arrays/fixed-length-read-only-length.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+ int foo[2] = { 23, 42 };
+ foo.length = 3;
+}
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 91bcee308..532dac240 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -292,6 +292,10 @@ public class Vala.Assignment : Expression {
return false;
}
}
+ } else if (ma.symbol_reference is ArrayLengthField && ((ArrayType)
ma.inner.value_type).inline_allocated) {
+ error = true;
+ Report.error (source_reference, "`length' field of fixed length arrays is
read-only");
+ return false;
} else if (ma.symbol_reference is Variable && right.value_type == null) {
var variable = (Variable) ma.symbol_reference;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]