[vala/wip/issue/658: 41/48] Added inner ownership test for anonymous delegates
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/658: 41/48] Added inner ownership test for anonymous delegates
- Date: Sat, 31 Oct 2020 15:08:17 +0000 (UTC)
commit 53104f63092cb4fe5dfc45a2babd89d8f69481bd
Author: Nick Schrader <nick schrader mailbox org>
Date: Sun Oct 25 23:39:31 2020 -0300
Added inner ownership test for anonymous delegates
tests/Makefile.am | 1 +
tests/delegates/anonymous-inner-owned-unowned.vala | 41 ++++++++++++++++++++++
2 files changed, 42 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ba5f24a1d..8c5e23412 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -342,6 +342,7 @@ TESTS = \
delegates/anonymous-array.vala \
delegates/anonymous-generics.test \
delegates/anonymous-inner-ref-out.vala \
+ delegates/anonymous-inner-owned-unowned.vala \
delegates/anonymous-optional-param.test \
delegates/anonymous-out.test \
delegates/anonymous-params.test \
diff --git a/tests/delegates/anonymous-inner-owned-unowned.vala
b/tests/delegates/anonymous-inner-owned-unowned.vala
new file mode 100644
index 000000000..e34e32c97
--- /dev/null
+++ b/tests/delegates/anonymous-inner-owned-unowned.vala
@@ -0,0 +1,41 @@
+[Compact]
+class Aaa {
+ public int i = 42;
+}
+
+class Bbb {
+ Aaa a = new Aaa();
+
+ public unowned Aaa get_a() {
+ unowned Aaa x = a;
+ a = null;
+ return x;
+ }
+}
+
+void p(delegate(owned Aaa) => void d) {
+ var a = new Aaa();
+ d ((owned) a);
+ assert (a == null);
+}
+
+void q(delegate(Aaa) => void d) {
+ var a = new Aaa();
+ d (a);
+ assert (a.i == 42);
+}
+
+void r(delegate() => Aaa d) {
+ assert (d ().i == 42);
+}
+
+void s(delegate() => unowned Aaa d) {
+ assert (d ().i != 42);
+}
+
+void main () {
+ p((a) => assert (a.i == 42));
+ q((a) => assert (a.i == 42));
+ r(() => new Aaa());
+ s(new Bbb().get_a);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]