]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Restore DestroysInstance behaviour for non-compact classes 42dca9175240a0cfa5c002c271eb53b29afe5b7a
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 6 Nov 2019 20:03:51 +0000 (21:03 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 6 Nov 2019 20:07:50 +0000 (21:07 +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 757cc0851494349199c323cdad571d8af76b2ba6..7b78d25ee6025b7e62d34a46e4c0481ea0dff659 100644 (file)
@@ -306,6 +306,7 @@ TESTS = \
        delegates/bug792077.vala \
        objects/chainup.vala \
        objects/class_only.vala \
+       objects/class-destroysinstance.vala \
        objects/class-inner-types.vala \
        objects/classes.vala \
        objects/classes-interfaces.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 e09c36551ddcad468024301059b7119113929019..b6b67bfcdb50279f203052580b6d57a90a1e3802 100644 (file)
@@ -944,7 +944,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 ();
                        }