summaryrefslogtreecommitdiff
path: root/tests/structs
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2021-04-12 09:21:48 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2021-04-12 09:24:12 +0200
commit3c69cebf43a9dd15d13b27889000599d42846348 (patch)
treeb8752155abe2e3149b3479e9ce75601ea3a021fb /tests/structs
parent1cb798d305f177a5f9492e74a2cc875ceaa8ad7b (diff)
downloadvala-3c69cebf43a9dd15d13b27889000599d42846348.tar.gz
codegen: Don't free unowned heap allocated struct
Regression of 63551acaf0d83fac8b50904c2759c1098fbfaa71
Diffstat (limited to 'tests/structs')
-rw-r--r--tests/structs/cast-struct-boxed.vala46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/structs/cast-struct-boxed.vala b/tests/structs/cast-struct-boxed.vala
index 97ccd1d7d..86fff4064 100644
--- a/tests/structs/cast-struct-boxed.vala
+++ b/tests/structs/cast-struct-boxed.vala
@@ -9,6 +9,11 @@ Foo? foo_heap_owned () {
return foo;
}
+unowned Foo? foo_heap_unowned () {
+ foo = { 42 };
+ return foo;
+}
+
void test_without_destroy () {
{
Foo f = foo_heap_owned ();
@@ -22,6 +27,18 @@ void test_without_destroy () {
Foo f = (!) foo_heap_owned ();
assert (f.i == 23);
}
+ {
+ Foo f = foo_heap_unowned ();
+ assert (f.i == 42);
+ }
+ {
+ Foo f = (Foo) foo_heap_unowned ();
+ assert (f.i == 42);
+ }
+ {
+ Foo f = (!) foo_heap_unowned ();
+ assert (f.i == 42);
+ }
}
struct Bar {
@@ -35,6 +52,11 @@ Bar? bar_heap_owned () {
return bar;
}
+unowned Bar? bar_heap_unowned () {
+ bar = { "manam" };
+ return bar;
+}
+
void test_with_destroy () {
{
Bar b = bar_heap_owned ();
@@ -48,6 +70,30 @@ void test_with_destroy () {
Bar b = (!) bar_heap_owned ();
assert (b.s == "bar");
}
+ {
+ Bar b = bar_heap_unowned ();
+ assert (b.s == "manam");
+ }
+ {
+ Bar b = (Bar) bar_heap_unowned ();
+ assert (b.s == "manam");
+ }
+ {
+ Bar b = (!) bar_heap_unowned ();
+ assert (b.s == "manam");
+ }
+ {
+ unowned Bar b = bar_heap_unowned ();
+ assert (b.s == "manam");
+ }
+ {
+ unowned Bar b = (Bar) bar_heap_unowned ();
+ assert (b.s == "manam");
+ }
+ {
+ unowned Bar b = (!) bar_heap_unowned ();
+ assert (b.s == "manam");
+ }
}
void main () {