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 530030 - Declaring "int a, b;" as member variable of a class results in parsing error
Declaring "int a, b;" as member variable of a class results in parsing error
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Objects
unspecified
Other All
: Low enhancement
: 2.0
Assigned To: Vala maintainers
Vala maintainers
: 592886 648184 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-04-26 09:20 UTC by Jaap A. Haitsma
Modified: 2018-05-22 13:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
suggested patch (15.48 KB, patch)
2008-05-05 06:42 UTC, Jared Moore
reviewed Details | Review
Allows declaration of multiple fields/constants on the same line (5.51 KB, patch)
2011-10-02 15:22 UTC, geert jordaens
none Details | Review

Description Jaap A. Haitsma 2008-04-26 09:20:56 UTC
Compiling example below

public class Sample {
        int a, b;

        static int main (string[] args) {
                int x, y;
                return 0;
        }
}

gives
/home/haitsma/blah.vala:3.7-3.7: error: syntax error, expected declaration
Comment 1 Jared Moore 2008-05-05 06:42:23 UTC
Created attachment 110390 [details] [review]
suggested patch

There is the same problem with const declarations, which are parsed differently from normal fields.

Another test case:

using GLib;
public class Sample {
        static const int i = 1, j = 2;
        static int a, b;

        static int main (string[] args) {
                int x, y;
                a = 3;
                b = 4;
                stdout.printf("%d ", i);
                stdout.printf("%d ", j);
                stdout.printf("%d ", a);
                stdout.printf("%d ", b);
                stdout.printf("\n");
                // Expected:
                // 1 2 3 4
                return 0;
        }
}

Suggested patch is attached.

Perhaps specialised singleton implementations of collections could be added to libgee, like in Java Collections [1]. If you agree then I'll file a new bug and patch for that :)

[1] http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#singleton(java.lang.Object)
Comment 2 Jürg Billeter 2008-05-07 20:31:48 UTC
Also see ideas in http://mail.gnome.org/archives/vala-list/2008-April/msg00135.html
Comment 3 Jürg Billeter 2008-05-07 20:34:04 UTC
Confirming, it can make sense in some cases to declare multiple fields on the same line. Thanks for the patch, Jared, I'll try to review it as soon as possible.
Comment 4 Jürg Billeter 2008-05-10 19:50:26 UTC
I'd like to avoid creating a new array list for each declaration as this costs about 10% of the overall performance. We could handle it similarly to parse_local_variable_declarations but that might make the code less clear. Maybe there is an other solution that keeps the code simple and is still performant.
Comment 5 Jared Moore 2008-05-11 08:45:42 UTC
Does that really affect the performance of the entire compiler that much? I really don't see any other nice way of implementing this. :/

I wrote an implementation of a singleton collection as mentioned in comment 1, which seems to have slightly better performance, but it seems like a bit of a premature optimisation. If you like I can clean it up a bit and upload that here or as a separate bug.
Comment 6 Jürg Billeter 2009-08-31 20:05:17 UTC
*** Bug 592886 has been marked as a duplicate of this bug. ***
Comment 7 Kenny Strawn 2010-12-11 15:44:56 UTC
Which version of valac does this bug affect? I have 0.12 on Ubuntu 11.04 "Natty Narwhal" Alpha 1 and still get this bug in a file where I wrote test code to basically draw two cube-oids on the screen (without any toolkit):

using GLib;

public class Box : GLib.Object {

    unsigned int Left;  //    
    unsigned int Top;   //Left, Top, Rear coordinate group
    unsigned int Rear;  // 

    unsigned int Right;  //
    unsigned int Bottom; //Right, Bottom, Front coordinate group
    unsigned int Front;  //

    public Box (int l, int t, int r1, int r2, int b, int f) { //Constructor
        
        l = Left;
        t = Top;
        r1 = Rear;

        r2 = Right;
        b = Bottom;
        f = Front;

    }

    public int main (string[] args) {

        var box_1 = new Box (0, 0, 0, 640, 480, 640);
        var box_2 = new Box (0, 0, 0, 600, 400, 600);

        return 0;
    }
}

I hope the patch gets applied upstream soon as member variables are essentially the guts of classes.
Comment 8 Jürg Billeter 2011-04-19 13:51:01 UTC
*** Bug 648184 has been marked as a duplicate of this bug. ***
Comment 9 geert jordaens 2011-10-02 15:22:01 UTC
Created attachment 198017 [details] [review]
Allows declaration of multiple fields/constants on the same line
Comment 10 GNOME Infrastructure Team 2018-05-22 13:05:27 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/6.