[vala/0.46] vala: Restore DestroysInstance behaviour for non-compact classes
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.46] vala: Restore DestroysInstance behaviour for non-compact classes
- Date: Thu, 7 Nov 2019 07:24:13 +0000 (UTC)
commit 6ede8e0df57e000134350a014f80ea13a7e1a936
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Nov 6 21:03:51 2019 +0100
vala: Restore DestroysInstance behaviour for non-compact classes
Although this attribute is not meant to be applied on methods of reference
counted classes, the original behaviour should not be changed silently.
Regression of 3d83f31a659bd179e8a867dd054126ac6f22e82b
Fixes https://gitlab.gnome.org/GNOME/vala/issues/873
tests/Makefile.am | 1 +
tests/objects/class-destroysinstance.vala | 15 +++++++++++++++
vala/valamemberaccess.vala | 3 ++-
3 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e13579755..2923d4cc5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -304,6 +304,7 @@ TESTS = \
delegates/bug792077.vala \
objects/chainup.vala \
objects/class_only.vala \
+ objects/class-destroysinstance.vala \
objects/classes.vala \
objects/classes-interfaces.vala \
objects/classes-interfaces-virtuals.vala \
diff --git a/tests/objects/class-destroysinstance.vala b/tests/objects/class-destroysinstance.vala
new file mode 100644
index 000000000..d5de16b62
--- /dev/null
+++ b/tests/objects/class-destroysinstance.vala
@@ -0,0 +1,15 @@
+class Foo : Object {
+ [DestroysInstance]
+ public void free () {
+ assert (this.ref_count == 2);
+ this.unref ();
+ }
+}
+
+void main () {
+ var foo = new Foo ();
+ {
+ foo.free ();
+ }
+ assert (foo.ref_count == 1);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index cbf251771..a1b0fe84c 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -916,7 +916,8 @@ public class Vala.MemberAccess : Expression {
}
if (symbol_reference is Method && ((Method) symbol_reference).get_attribute
("DestroysInstance") != null) {
- if (ma != null) {
+ unowned Class? cl = ((Method) symbol_reference).parent_symbol as Class;
+ if (cl != null && cl.is_compact && ma != null) {
ma.lvalue = true;
ma.check_lvalue_access ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]