summaryrefslogtreecommitdiff
path: root/tests/structs
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2021-04-11 20:45:59 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2021-04-11 20:45:59 +0200
commit5ac884082e956eef62e6a1013059f9aa65ce94ba (patch)
tree445dd595634faa505aa068500401f8daf8d6cd5c /tests/structs
parentc9c7c782f02843061fa9d13dfba917ad8f295272 (diff)
downloadvala-5ac884082e956eef62e6a1013059f9aa65ce94ba.tar.gz
codegen: Don't free temp-var for element-access to array with boxed structs (2)
See https://gitlab.gnome.org/GNOME/vala/issues/1174
Diffstat (limited to 'tests/structs')
-rw-r--r--tests/structs/cast-struct-boxed.vala56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/structs/cast-struct-boxed.vala b/tests/structs/cast-struct-boxed.vala
new file mode 100644
index 000000000..97ccd1d7d
--- /dev/null
+++ b/tests/structs/cast-struct-boxed.vala
@@ -0,0 +1,56 @@
+struct Foo {
+ public int i;
+}
+
+Foo? foo;
+
+Foo? foo_heap_owned () {
+ foo = { 23 };
+ return foo;
+}
+
+void test_without_destroy () {
+ {
+ Foo f = foo_heap_owned ();
+ assert (f.i == 23);
+ }
+ {
+ Foo f = (Foo) foo_heap_owned ();
+ assert (f.i == 23);
+ }
+ {
+ Foo f = (!) foo_heap_owned ();
+ assert (f.i == 23);
+ }
+}
+
+struct Bar {
+ public string s;
+}
+
+Bar? bar;
+
+Bar? bar_heap_owned () {
+ bar = { "bar" };
+ return bar;
+}
+
+void test_with_destroy () {
+ {
+ Bar b = bar_heap_owned ();
+ assert (b.s == "bar");
+ }
+ {
+ Bar b = (Bar) bar_heap_owned ();
+ assert (b.s == "bar");
+ }
+ {
+ Bar b = (!) bar_heap_owned ();
+ assert (b.s == "bar");
+ }
+}
+
+void main () {
+ test_without_destroy ();
+ test_with_destroy ();
+}