From: Rico Tzschichholz Date: Wed, 6 Nov 2019 20:03:51 +0000 (+0100) Subject: vala: Restore DestroysInstance behaviour for non-compact classes X-Git-Tag: 0.44.10~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3356f17f55584002aef412efbdee84fab5c7df8e;p=thirdparty%2Fvala.git 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 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index cb6b69912..9b37e3483 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 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 (); }