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.47.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42dca9175240a0cfa5c002c271eb53b29afe5b7a;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 757cc0851..7b78d25ee 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 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 e09c36551..b6b67bfcd 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -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 (); }