summaryrefslogtreecommitdiff
path: root/tests/structs
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2020-06-17 19:26:55 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2020-06-18 10:56:47 +0200
commit68db26a5a26338ce2ccb586d4a7eb109f4a3bbcf (patch)
tree7f4d97616f72a49b166f626347e05751bd1c8844 /tests/structs
parent6485bca67e2dfd92037e50c752c067d40ed448da (diff)
downloadvala-68db26a5a26338ce2ccb586d4a7eb109f4a3bbcf.tar.gz
codegen: Cast initializer-list to struct for non-constant/non-array assignments
Avoid invalid c-code and use the correct syntax for compound literals. Fixes https://gitlab.gnome.org/GNOME/vala/issues/1013
Diffstat (limited to 'tests/structs')
-rw-r--r--tests/structs/struct-initializer-list-nested.vala63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/structs/struct-initializer-list-nested.vala b/tests/structs/struct-initializer-list-nested.vala
new file mode 100644
index 000000000..dc5a48f21
--- /dev/null
+++ b/tests/structs/struct-initializer-list-nested.vala
@@ -0,0 +1,63 @@
+struct Foo {
+ int i;
+ int j;
+}
+
+struct Bar {
+ Foo a;
+ Foo? b;
+}
+
+struct Manam {
+ Foo a;
+ Bar b;
+}
+
+struct Baz {
+ Foo f;
+}
+
+const Baz BAZ = { { 23, 42 } };
+
+const Baz[] BAZ_A = { { { 23, 42 } }, { { 47, 11 } } };
+
+void main () {
+ {
+ const Baz LOCAL_BAZ = { { 23, 42 } };
+ }
+ {
+ const Baz[] LOCAL_BAZ_A = { { { 23, 42 } }, { { 47, 11 } } };
+ }
+ {
+ Bar bar = { { 23 , 47 }, { 42, 11 } };
+ assert (bar.a.j == 47);
+ assert (bar.b.i == 42);
+ }
+ {
+ Bar? bar = { { 23 , 47 }, { 42, 11 } };
+ assert (bar.a.i == 23);
+ assert (bar.b.j == 11);
+ }
+ {
+ Bar bar = {};
+ bar = { { 23 , 47 }, { 42, 11 } };
+ assert (bar.a.j == 47);
+ assert (bar.b.i == 42);
+ }
+ {
+ Manam manam = { { 23, 42 }, { { 23 , 47 }, { 42, 11 } } };
+ assert (manam.a.i == 23);
+ assert (manam.b.b.j == 11);
+ }
+ {
+ Manam manam = {};
+ manam = { { 23, 42 }, { { 23 , 47 }, { 42, 11 } } };
+ assert (manam.a.i == 23);
+ assert (manam.b.b.j == 11);
+ }
+ {
+ Manam? manam = { { 23, 42 }, { { 23 , 47 }, { 42, 11 } } };
+ assert (manam.a.j == 42);
+ assert (manam.b.a.i == 23);
+ }
+}