[vala/staging] vala: Infer array length of inline allocated arrays for fields
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Infer array length of inline allocated arrays for fields
- Date: Tue, 29 Oct 2019 16:30:24 +0000 (UTC)
commit ff3ec833e0ed28dabf61d66c52dc67e473e3551a
Author: Florian Brosch <flo brosch gmail com>
Date: Thu Sep 18 05:09:03 2014 +0200
vala: Infer array length of inline allocated arrays for fields
Don't allow non-arrays as initializer for inline allocated arrays
Same as 0f0bca7e0519af13d9217fbca2c20ce67cd3baba
See https://bugzilla.gnome.org/show_bug.cgi?id=644046
vala/valafield.vala | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
---
diff --git a/vala/valafield.vala b/vala/valafield.vala
index 6e7c6f471..f3a81f0e3 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -120,6 +120,15 @@ public class Vala.Field : Variable, Lockable {
if (initializer != null) {
initializer.target_type = variable_type;
+ // Catch initializer list transformation:
+ bool is_initializer_list = false;
+ int initializer_size = -1;
+
+ if (initializer is InitializerList) {
+ initializer_size = ((InitializerList) initializer).size;
+ is_initializer_list = true;
+ }
+
if (!initializer.check (context)) {
error = true;
return false;
@@ -137,6 +146,18 @@ public class Vala.Field : Variable, Lockable {
return false;
}
+ if (variable_array_type != null && variable_array_type.inline_allocated &&
!variable_array_type.fixed_length && is_initializer_list) {
+ variable_array_type.length = new IntegerLiteral (initializer_size.to_string
());
+ variable_array_type.fixed_length = true;
+ variable_array_type.nullable = false;
+ }
+
+ if (variable_array_type != null && variable_array_type.inline_allocated &&
!(initializer.value_type is ArrayType)) {
+ error = true;
+ Report.error (source_reference, "only arrays are allowed as initializer for
arrays with fixed length");
+ return false;
+ }
+
if (initializer.value_type.is_disposable ()) {
/* rhs transfers ownership of the expression */
if (!(variable_type is PointerType) && !variable_type.value_owned) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]