GNOME Bugzilla – Bug 790239
Namespace with certain identifiers creates invalid C code
Last modified: 2018-05-22 15:56:29 UTC
I see two issues here: -------------------------------- namespace 123x { const int a = 42; } int main() { return 0; } -------------------------------- % valac -c y.vala /tmp/y.vala.c:11:9: error: macro name must be an identifier #define 123X_a 42 ^ 1 error generated. error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s) Obviously this "acceptable" Vala program creates invalid C code, whereas it should rather emit a Vala error, since 123x is not a legal identifier (identifiers in Vala which start w/ digits have to be escaped). However, trying to make it a legal identifier by adding the '@' does not cut it either: -------------------------------- namespace @123x { const int a = 42; } int main() { return 0; } -------------------------------- % valac -c y.vala /tmp/y.vala.c:11:9: error: macro name must be an identifier #define 123X_a 42 ^ 1 error generated. error: cc exited with status 256
This is part of a wider problem of identifier verification in Vala. The GLib naming convention is "Type names (including object names) must be at least three characters long and start with ‘a–z’, ‘A–Z’ or ‘_’" See https://developer.gnome.org/gobject/stable/gtype-conventions.html I think there should probably be some identifier validation functions, like: bool identifier_matches_glib_naming_conventions (Node node) {} and bool identifier_matches_c_naming_conventions (Node node) {} The more difficult part is understanding how any validation done by iterating over the Vala AST interacts with later C code generation, but this is purely relating to identifier name translation to C. Name translation to C should be self contained. For example see CCodeBaseModule.get_ccode_name () and https://bugzilla.gnome.org/show_bug.cgi?id=788837 I'm not sure @ should do anything in the example @123x, it should probably be treated as an invalid starting character because 123x is not a keyword. As far as I know @ is just used to override a keyword conflict error message. I agree that robust handling of identifier names is a basic requirement for a 1.0 release.
*** Bug 611150 has been marked as a duplicate of this bug. ***
*** Bug 671456 has been marked as a duplicate of this bug. ***
*** Bug 670022 has been marked as a duplicate of this bug. ***
-- 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/602.