GNOME Bugzilla – Bug 683925
If you declare a delegate with a default value, the closure for that default value is broken.
Last modified: 2017-03-22 16:08:13 UTC
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"); stderr.flush(); stdout.printf("mydelegate returned %s\n", result); mydelegate=otherfun; result = mydelegate("blebleble"); stdout.printf("mydelegate returned %s\n", result); } } void main(){ var t1=new Test_delegates(); t1.run(); } Shows: ** (process:8090): CRITICAL **: test_delegates_defaultfun: assertion `self != NULL' failed
Created attachment 348513 [details] [review] codegen: Fix delegate initializer for instance fields Set delegate-target to "self" which is available in *_instance_init().
Attachment 348513 [details] pushed as db6f68f - codegen: Fix delegate initializer for instance fields