Owned delegate still frees compact class
I stumbled across the following code:
void main () {
var b = new Bbb();
b.set_d (new Aaa().get_i);
b.do_stuff ();
}
[Compact]
class Aaa {
public int i = 42;
public int get_i () {
return i;
}
}
class Bbb {
public delegate int D();
D d;
public void set_d(owned D d) {
this.d = (owned) d;
}
public void do_stuff() {
assert (d () == 42);
}
}
IMHO, b
should hold a reference to d
and hence to the Aaa
-instance for its lifetime as we transferred ownership. However, the instance is directly freed after b.set_d()
.
In the generated C-code we can see how the instance (_tmp2_
) is passed as a target to bbb_set_d()
, but then freed in the next line:
void
_vala_main (void)
{
Bbb* b = NULL;
Bbb* _tmp0_;
Aaa* _tmp1_;
Aaa* _tmp2_;
_tmp0_ = bbb_new ();
b = _tmp0_;
_tmp1_ = aaa_new ();
_tmp2_ = _tmp1_;
bbb_set_d (b, _aaa_get_i_bbb_d, _tmp2_, NULL);
_aaa_free0 (_tmp2_);
bbb_do_stuff (b);
_bbb_unref0 (b);
}
Or did I miss something?