[vala/0.46] 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.46] vala: Do not allow to change .length of arrays with fixed length
- Date: Wed, 30 Oct 2019 07:45:44 +0000 (UTC)
commit efb5479f7033d91b3d82e8d6c7636db33d848cfd
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 9db0ec163..0920a48fb 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -290,6 +290,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]