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 647018 - Valac doesn't check for invalid identifiers
Valac doesn't check for invalid identifiers
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Parser
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-04-07 11:32 UTC by davorin
Modified: 2014-04-06 13:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Check/mangle invalid field/local names (1.50 KB, patch)
2014-04-06 11:06 UTC, Simon Werbeck
needs-work Details | Review
Check/mangle invalid field/local names (3.38 KB, patch)
2014-04-06 12:06 UTC, Simon Werbeck
needs-work Details | Review
Check/mangle invalid field/local names (3.42 KB, patch)
2014-04-06 12:15 UTC, Simon Werbeck
none Details | Review

Description davorin 2011-04-07 11:32:49 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
Comment 1 Simon Werbeck 2014-04-06 11:06:34 UTC
Created attachment 273656 [details] [review]
Check/mangle invalid field/local names

Fixes bug 647018
Comment 2 Luca Bruno 2014-04-06 11:11:43 UTC
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;
Comment 3 Simon Werbeck 2014-04-06 12:06:16 UTC
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
Comment 4 Luca Bruno 2014-04-06 12:10:22 UTC
Review of attachment 273660 [details] [review]:

Better, can we please put the test case in some subdir? objects/ should be ok.
Comment 5 Simon Werbeck 2014-04-06 12:15:21 UTC
Created attachment 273661 [details] [review]
Check/mangle invalid field/local names

Done :)
Comment 6 Luca Bruno 2014-04-06 13:56:11 UTC
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.