Re: [Vala] Bug: badly crafted closures in delegates with default values

Sorry, something broke along the way.

Here is (i hope) in plaintext:

Good morning everyone.
I have found a bug in Vala.
If you declare a delegate with a default value, the closure for that default value is broken. See this code:

class Test_delegates : Object {
    public delegate string delegateType1(string param);

public delegateType1 mydelegate=defaultfun; //This default initialization is badly made. The closure does not include the current instance of Test_delegates

    public Test_delegates(){
//mydelegate = defaultfun; //This initialization works. Uncomment to see it working.

    public string defaultfun(string param){
        stdout.printf("defaultfun received %s\n", param);
        string retorno = "### %s ###".printf(param);
        stdout.printf("defaultfun returns %s\n", retorno);
        return retorno;

    public string otherfun(string param){
        stdout.printf("otherfun received %s\n", param);
        string retorno = "@@@ %s @@@".printf(param);
        stdout.printf("otherfun returns %s\n", retorno);
        return retorno;

    public void run(){
        string result = mydelegate("blebleble");
        stdout.printf("mydelegate returned %s\n", result);
        result = mydelegate("blebleble");
        stdout.printf("mydelegate returned %s\n", result);

void main(){
    var t1=new Test_delegates();;

** (process:8090): CRITICAL **: test_delegates_defaultfun: assertion `self != NULL' failed

Tested with Vala 0.17.5.

Best regards,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]