[Vala] [BUG] Cannot store delegate in a class.
- From: Jan Hudec <bulb ucw cz>
- To: vala-list gnome org
- Subject: [Vala] [BUG] Cannot store delegate in a class.
- Date: Fri, 18 Sep 2009 21:54:11 +0200
Hello folks,
Until recently, I could store a delegate in a class. It was incorrect in many
cases because a destroy notify was not stored in the delegates.
Now the destroy notify is stored, but for some reason fails to be stored in
a class. What is worse, vala does not report any error and silently generates
invalid code:
Case 1:
delegate bool Predicate();
class Checker {
private Predicate predicate;
public Checker(Predicate predicate) {
this.predicate = predicate;
}
}
int main(string[] argv) {
bool result = true;
var checker = new Checker(() => result);
return 0;
}
This compiled in 0.7.5 (though without the destroy notify it was not really
correct), but now it produces invalid code. This particualr snippet gives:
/tmp/test1.vala.c: In function ‘checker_construct’:
/tmp/test1.vala.c:77: error: ‘predicate_target_destroy_notify’ undeclared (first use in this function)
/tmp/test1.vala.c:77: error: (Each undeclared identifier is reported only once
/tmp/test1.vala.c:77: error: for each function it appears in.)
error: cc exited with status 256
Compilation failed: 1 error(s), 1 warning(s)
(and a warning that checker is unused, which is correct)
Expected result:
Either working code, or vala error that delegate cannot be copied.
Case 2:
delegate bool Predicate();
class Checker {
private Predicate predicate;
public Checker(owned Predicate predicate) {
this.predicate = predicate;
}
}
int main(string[] argv) {
bool result = true;
var checker = new Checker(() => result);
return 0;
}
Since the destroy_notify is defined for owned delegates, I tried making the
constructor parameter owned. It however produces the following error:
/tmp/test2.vala.c: In function ‘checker_construct’:
/tmp/test2.vala.c:77: error: lvalue required as left operand of assignment
/tmp/test2.vala.c: In function ‘_main’:
/tmp/test2.vala.c:261: warning: passing argument 3 of ‘checker_new’ from incompatible pointer type
error: cc exited with status 256
Compilation failed: 1 error(s), 1 warning(s)
(and a warning that checker is unused, which is correct)
Expected result:
Working code.
I also tried declaring the member 'owned', but that gave me a syntax error
from vala (because it should be owned by default, shouldn't it?)
It might be the same problem as
https://bugzilla.gnome.org/show_bug.cgi?id=592769. It was reported some time
ago while I am quite confident the Case 1 above still compiled yesterday, but
it might be that the recent changes to owned delegate handling just expanded
scope of the existing problem.
--
Jan 'Bulb' Hudec <bulb ucw cz>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]