[vala/0.52: 4/4] vala: Disallow resize() for constant arrays
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.52: 4/4] vala: Disallow resize() for constant arrays
- Date: Mon, 16 Aug 2021 10:18:31 +0000 (UTC)
commit c47d6c0106a8556480ff00e54b6eae0161582bc3
Author: wxx <769218589 qq com>
Date: Tue Aug 3 23:07:49 2021 +0800
vala: Disallow resize() for constant arrays
See https://gitlab.gnome.org/GNOME/vala/issues/944
tests/Makefile.am | 1 +
tests/arrays/resize-constant.test | 6 ++++++
vala/valamemberaccess.vala | 22 ++++++++++++++--------
3 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 66a20f883..7c04805a9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -129,6 +129,7 @@ TESTS = \
arrays/struct-namespaced-initializer.vala \
arrays/incompatible-integer-elements.test \
arrays/resize.vala \
+ arrays/resize-constant.test \
arrays/resize-local-size.vala \
arrays/resize-local-size-captured.vala \
arrays/resize-unowned-invalid.test \
diff --git a/tests/arrays/resize-constant.test b/tests/arrays/resize-constant.test
new file mode 100644
index 000000000..277db85af
--- /dev/null
+++ b/tests/arrays/resize-constant.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+ const int[] foo = { 1, 2, 3 };
+ foo.resize (2);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index ae8079bd2..9a9b8cf5c 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -509,14 +509,20 @@ public class Vala.MemberAccess : Expression {
}
}
- if (symbol_reference is ArrayResizeMethod && inner.symbol_reference is Variable) {
- // require the real type with its original value_owned attritubte
- var inner_type = context.analyzer.get_value_type_for_symbol
(inner.symbol_reference, true) as ArrayType;
- if (inner_type != null && inner_type.inline_allocated) {
- Report.error (source_reference, "`resize' is not supported for arrays
with fixed length");
- error = true;
- } else if (inner_type != null && !inner_type.value_owned) {
- Report.error (source_reference, "`resize' is not allowed for unowned
array references");
+ if (symbol_reference is ArrayResizeMethod) {
+ if (inner.symbol_reference is Variable) {
+ // require the real type with its original value_owned attritubte
+ var inner_type = context.analyzer.get_value_type_for_symbol
(inner.symbol_reference, true) as ArrayType;
+ if (inner_type != null && inner_type.inline_allocated) {
+ Report.error (source_reference, "`resize' is not supported
for arrays with fixed length");
+ error = true;
+ } else if (inner_type != null && !inner_type.value_owned) {
+ Report.error (source_reference, "`resize' is not allowed for
unowned array references");
+ error = true;
+ }
+ } else if (inner.symbol_reference is Constant) {
+ // disallow resize() for const array
+ Report.error (source_reference, "`resize' is not allowed for constant
arrays");
error = true;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]