After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 639017 - "warning: assignment from incompatible pointer type" when accessing a parent scope variable in a delegate function.
"warning: assignment from incompatible pointer type" when accessing a parent ...
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Code Generator
0.10.x
Other Linux
: Normal minor
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks: 664084
 
 
Reported: 2011-01-08 17:41 UTC by Dwight Schauer
Modified: 2018-05-22 13:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Generated C source (2.15 KB, text/x-csrc)
2011-01-08 17:41 UTC, Dwight Schauer
Details

Description Dwight Schauer 2011-01-08 17:41:57 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
*/
Comment 1 Dwight Schauer 2011-01-09 02:51:35 UTC
Tried again with valac 0.11.2, same result. Gives warning, but still works.
Comment 2 Michael 'Mickey' Lauer 2018-02-21 11:07:41 UTC
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)
                ^
Comment 3 GNOME Infrastructure Team 2018-05-22 13:51:10 UTC
-- 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.