GNOME Bugzilla – Bug 628756
if main function is in a class called main bad C code generated
Last modified: 2018-05-22 13:44:23 UTC
If the main "function" is in a class called main bad C code generated. Example: /* example.gs - Begin example code */ class main def static main (args : array of string) : int return 0 /* example.gs - End example code */ Compilation: $ valac example.gs -o example example.vala.c:67: error: ‘main’ redeclared as different kind of symbol example.vala.c:20: note: previous declaration of ‘main’ was here example.vala.c:73: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token example.vala.c:80: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token example.vala.c: In function ‘value_main_collect_value’: example.vala.c:113: error: ‘object’ undeclared (first use in this function) example.vala.c:113: error: (Each undeclared identifier is reported only once example.vala.c:113: error: for each function it appears in.) example.vala.c: In function ‘value_main_lcopy_value’: example.vala.c:129: error: ‘object_p’ undeclared (first use in this function) example.vala.c: In function ‘value_set_main’: example.vala.c:161: error: ‘old’ undeclared (first use in this function) example.vala.c: In function ‘value_take_main’: example.vala.c:179: error: ‘old’ undeclared (first use in this function) example.vala.c: At top level: example.vala.c:201: error: expected ‘)’ before ‘*’ token example.vala.c:206: error: expected ‘)’ before ‘*’ token example.vala.c: In function ‘main_get_type’: example.vala.c:216: error: ‘main_instance_init’ undeclared (first use in this function) example.vala.c: In function ‘main_ref’: example.vala.c:227: error: ‘self’ undeclared (first use in this function) example.vala.c: In function ‘main_unref’: example.vala.c:235: error: ‘self’ undeclared (first use in this function) error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s)
It's hard to make Vala detect all name collisions because it will fail if any C include file or any other static method/variable using the same name. It is possible to control those issues at codegen-level. But only if the collision happens on Vala code. Vala should have a reserved blacklist for method/variable names. What do you devs think?
Also, this issue can be reproduced on latest Vala 0.18.1 and also breaks on Vala (not only Genie). It's a codegen issue.
-- 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/130.