]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Restore DestroysInstance behaviour for non-compact classes
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 6 Nov 2019 20:03:51 +0000 (21:03 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 7 Nov 2019 11:11:49 +0000 (12:11 +0100)
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
tests/objects/class-destroysinstance.vala [new file with mode: 0644]
vala/valamemberaccess.vala

index cb6b699120ebc7140d9f3e5ff16c6f97eb55c0f6..9b37e348373e2be5d1ae174c79fead91159c8f76 100644 (file)
@@ -300,6 +300,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 (file)
index 0000000..d5de16b
--- /dev/null
@@ -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);
+}
index cbf25177107fc870f35e994e014ce4cce90f3d0f..a1b0fe84cda16bf12e5ff0067d15fcb2e4dd251c 100644 (file)
@@ -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 ();
                        }