"warning: assignment from incompatible pointer type" when accessing a parent scope variable in a delegate function.
Submitted by Dwight Schauer
Link to original bug (#639017)
Description
Created attachment 177841 Generated C source
/* The following peice of code generates a warning, but the code still works. */
delegate void MyDel (int a, string b);
static int main (string[] args) {
int c = 10;
MyDel myDel = (a,b) => { stdout.printf ("a:%d b:%s c:%d\n", a, b, c); c = 40; };
myDel (5, "test");
stdout.printf ("c:%d\n", c);
return 0; }
/* When compiling it gives a warning, but it still runs $ valac -o foo delegate-incompatible-pointer-warning.vala /tmp/bug-test/delegate-incompatible-pointer-warning.vala.c: In function ‘_vala_main’: /tmp/bug-test/delegate-incompatible-pointer-warning.vala.c:64:109: warning: assignment from incompatible pointer type
$ ./foo a:5 b:test c:10 c:40 */
// Here are the relevant portions from the c output:
#if 0
static Block1Data* block1_data_ref (Block1Data* data1) {
g_atomic_int_inc (&data1->_ref_count_);
return data1;
}
// <snip>
GDestroyNotify myDel_target_destroy_notify = NULL;
// <snip>
myDel = (tmp0 = __lambda0__my_del, myDel_target = block1_data_ref (data1), myDel_target_destroy_notify = block1_data_unref, tmp0);
#endif
/* If I cast block1_data_unref to GDestroyNotify the warning goes away */
Attachment 177841, "Generated C source":
delegate-incompatible-pointer-warning.c
Version: 0.10.x