GNOME Bugzilla – Bug 639017
"warning: assignment from incompatible pointer type" when accessing a parent scope variable in a delegate function.
Last modified: 2018-05-22 13:51:10 UTC
Created attachment 177841 [details] 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 */
Tried again with valac 0.11.2, same result. Gives warning, but still works.
With Vala master, this warning is gone on gcc. clang reports another one though: % valac --save-temps bug639017.vala /Volumes/ramdisk/vala/bug639017.c:95:42: warning: expression result unused; should this cast be to 'void'? [-Wunused-value] (myDel_target_destroy_notify == NULL) ? NULL : (myDel_target_destroy_notify (myDel_target), NULL); ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include/stddef.h:105:17: note: expanded from macro 'NULL' # define NULL ((void*)0) ^
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/155.