[vala/0.40] vala: Inline allocated arrays require length or initializer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] vala: Inline allocated arrays require length or initializer
- Date: Wed, 5 Feb 2020 10:04:06 +0000 (UTC)
commit 31800954ce97246fc15fccffe10c5a893eab21a5
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Feb 1 14:47:00 2020 +0100
vala: Inline allocated arrays require length or initializer
Fixes https://gitlab.gnome.org/GNOME/vala/issues/903
tests/Makefile.am | 4 ++++
tests/arrays/inline-field.test | 6 ++++++
tests/arrays/inline-local-variable.test | 5 +++++
tests/arrays/inline-parameter.test | 7 +++++++
tests/arrays/inline-struct-field.test | 8 ++++++++
vala/valafield.vala | 5 +++++
vala/valalocalvariable.vala | 5 +++++
vala/valaparameter.vala | 6 ++++++
8 files changed, 46 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5e246d108..d312b0dc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -69,6 +69,10 @@ TESTS = \
arrays/fixed-length-concat-invalid.test \
arrays/fixed-length-non-const.test \
arrays/fixed-length-resize-invalid.test \
+ arrays/inline-field.test \
+ arrays/inline-local-variable.test \
+ arrays/inline-parameter.test \
+ arrays/inline-struct-field.test \
arrays/length-inline-assignment.vala \
arrays/struct-field-length-cname.vala \
arrays/slice-invalid-start.test \
diff --git a/tests/arrays/inline-field.test b/tests/arrays/inline-field.test
new file mode 100644
index 000000000..e7f419da4
--- /dev/null
+++ b/tests/arrays/inline-field.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+int bar[];
+
+void main () {
+}
diff --git a/tests/arrays/inline-local-variable.test b/tests/arrays/inline-local-variable.test
new file mode 100644
index 000000000..ebcb4f377
--- /dev/null
+++ b/tests/arrays/inline-local-variable.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+ int manam[];
+}
diff --git a/tests/arrays/inline-parameter.test b/tests/arrays/inline-parameter.test
new file mode 100644
index 000000000..3802e498e
--- /dev/null
+++ b/tests/arrays/inline-parameter.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo (int bar[]) {
+}
+
+void main () {
+}
diff --git a/tests/arrays/inline-struct-field.test b/tests/arrays/inline-struct-field.test
new file mode 100644
index 000000000..eba1c1ce3
--- /dev/null
+++ b/tests/arrays/inline-struct-field.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+struct Foo {
+ public int bar[];
+}
+
+void main () {
+}
diff --git a/vala/valafield.vala b/vala/valafield.vala
index 4f7594e01..7bf66b78a 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -128,6 +128,11 @@ public class Vala.Field : Variable, Lockable {
initializer = null;
}
+ if (variable_array_type != null && variable_array_type.inline_allocated
+ && !variable_array_type.fixed_length) {
+ Report.error (source_reference, "Inline allocated array as field requires to have
fixed length");
+ }
+
if (initializer != null) {
initializer.target_type = variable_type;
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index f54954325..8654a982b 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -137,6 +137,11 @@ public class Vala.LocalVariable : Variable {
initializer = null;
}
+ if (variable_array_type != null && variable_array_type.inline_allocated
+ && variable_array_type.length == null && !(initializer is ArrayCreationExpression)) {
+ Report.error (source_reference, "Inline allocated array requires either a given
length or an initializer");
+ }
+
if (initializer != null && !initializer.error) {
if (initializer.value_type == null) {
if (!(initializer is MemberAccess) && !(initializer is LambdaExpression)) {
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index 39820718c..a211345f4 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -167,6 +167,12 @@ public class Vala.Parameter : Variable {
initializer.target_type = variable_type.copy ();
initializer.check (context);
}
+
+ unowned ArrayType? variable_array_type = variable_type as ArrayType;
+ if (variable_array_type != null && variable_array_type.inline_allocated
+ && !variable_array_type.fixed_length) {
+ Report.error (source_reference, "Inline allocated array as parameter requires
to have fixed length");
+ }
}
if (initializer != null) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]