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 790239 - Namespace with certain identifiers creates invalid C code
Namespace with certain identifiers creates invalid C code
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Code Generator
unspecified
Other All
: Normal normal
: 1.0
Assigned To: Vala maintainers
Vala maintainers
: 611150 670022 671456 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-11-12 11:19 UTC by Michael 'Mickey' Lauer
Modified: 2018-05-22 15:56 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael 'Mickey' Lauer 2017-11-12 11:19:09 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
Comment 1 Al Thomas 2017-11-12 18:22:37 UTC
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.
Comment 2 Rico Tzschichholz 2018-02-19 09:56:24 UTC
*** Bug 611150 has been marked as a duplicate of this bug. ***
Comment 3 Michael 'Mickey' Lauer 2018-02-21 13:22:49 UTC
*** Bug 671456 has been marked as a duplicate of this bug. ***
Comment 4 Michael 'Mickey' Lauer 2018-02-21 13:23:57 UTC
*** Bug 670022 has been marked as a duplicate of this bug. ***
Comment 5 GNOME Infrastructure Team 2018-05-22 15:56:29 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/602.