const variable may clash with other symbols in generated C
Minimal example:
const string code = "demo";
int main (string[] args) {
FileUtils.set_contents("demo", code);
return 0;
}
Error:
In file included from /usr/include/glib-2.0/glib.h:62,
from /home/zbrown/icg.vala.c:6:
/home/zbrown/icg.vala.c: In function ‘_vala_main’:
/home/zbrown/icg.vala.c:9:14: error: expected identifier before string constant
9 | #define code "demo"
| ^~~~~~
/usr/include/glib-2.0/glib/gmessages.h:336:32: note: in definition of macro ‘g_critical’
336 | __VA_ARGS__)
| ^~~~~~~~~~~
/home/zbrown/icg.vala.c:23:169: note: in expansion of macro ‘code’
23 | g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
| ^~~~
error: cc exited with status 256
The problem lies in the generated error handler
if (G_UNLIKELY (_inner_error0_ != NULL)) {
gint _tmp0_ = -1;
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
g_clear_error (&_inner_error0_);
return _tmp0_;
}
The C Preprocessor having "helpfully" expanded _inner_error0_->code
to _inner_error0_->"demo"