Skip to content

Commit

Permalink
vala: Restore DestroysInstance behaviour for non-compact classes
Browse files Browse the repository at this point in the history
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 3d83f31

Fixes https://gitlab.gnome.org/GNOME/vala/issues/873
  • Loading branch information
ricotz committed Nov 7, 2019
1 parent 6040c10 commit 6ede8e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/Makefile.am
Expand Up @@ -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 \
Expand Down
15 changes: 15 additions & 0 deletions 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);
}
3 changes: 2 additions & 1 deletion vala/valamemberaccess.vala
Expand Up @@ -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 ();
}
Expand Down

0 comments on commit 6ede8e0

Please sign in to comment.