GNOME Bugzilla – Bug 647018
Valac doesn't check for invalid identifiers
Last modified: 2014-04-06 13:56:11 UTC
Valac (0.12.0-0ubuntu1) allows 2sqrtA as an identifier although the first character is a digit. float 2sqrtA = 2f * (float) sqrt(A); The C compiler then outputs the error: error: invalid suffix "sqrtA" on integer constant error: cc exited with status 256
Created attachment 273656 [details] [review] Check/mangle invalid field/local names Fixes bug 647018
Review of attachment 273656 [details] [review]: Thanks for the patch, pointing out a couple of things. ::: codegen/valaccodebasemodule.vala @@ +2238,3 @@ public string get_local_cname (LocalVariable local) { var cname = get_variable_cname (local.name); + if (local.name[0].isdigit ()) { Check the cname[0] to be digit, not the local name. ::: vala/valaparser.vala @@ +2508,3 @@ var type = parse_type (true, true); string id = parse_identifier (); + if (id[0].isdigit ()) { In vala this is possible, and should not be forbidden here. The cname in the codegen must be checked. You may have: [CCode (cname = "foo")] public int 2foo;
Created attachment 273660 [details] [review] Check/mangle invalid field/local names I made the suggested changes. However, now a field starting with a digit must also provide a cname attribute. Fixes bug 647018
Review of attachment 273660 [details] [review]: Better, can we please put the test case in some subdir? objects/ should be ok.
Created attachment 273661 [details] [review] Check/mangle invalid field/local names Done :)
commit 0d449a938dc2153a9b70ba4bcef35a8f1a421aa6 Author: Simon Werbeck <simon.werbeck@gmail.com> Date: Sun Apr 6 13:04:04 2014 +0200 codegen: Fix local and field names starting with a digit Fixes bug 647018 This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.