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 530623 - Support local constants
Support local constants
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Methods
0.3.x
Other All
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
: 541152 589603 601341 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-04-29 20:05 UTC by Jürg Billeter
Modified: 2010-10-13 20:19 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jürg Billeter 2008-04-29 20:05:31 UTC
We should add support for local constants, i.e. constants within methods. We should probably support more inner declarations in methods in general, e.g. inner methods.
Comment 1 Jaap A. Haitsma 2008-07-02 06:10:25 UTC
*** Bug 541152 has been marked as a duplicate of this bug. ***
Comment 2 Jürg Billeter 2009-07-27 15:19:58 UTC
*** Bug 589603 has been marked as a duplicate of this bug. ***
Comment 3 Jürg Billeter 2010-01-08 22:15:31 UTC
*** Bug 601341 has been marked as a duplicate of this bug. ***
Comment 4 pancake 2010-03-10 10:43:27 UTC
Here's a simple test case.

int main() {
        const int foo = 33;
        return foo;
}

We should provide at least a helpful error message insteaf of 'syntax error, expected ';'' If they are local they can be replaced inline in code or just use 'const' attribute in C code generation. It should be the same effect at compile time.
Comment 5 Marc-Andre Lureau 2010-03-10 10:44:00 UTC
inner function with outer scope? :)
Comment 6 pancake 2010-06-01 11:33:50 UTC
I think local constants should be expanded instead of #define This will fix many issues related to constants named as keywords or function names which results in even weirdest errors.
Comment 7 pancake 2010-06-01 11:35:05 UTC
Another solution would be to just #define and #undef at the end of the function.

int class_method_function() {
#define CLASS_METHOD_CONSTNAME value
   ...
#undef CLASS_METHOD_CONSTNAME
}
Comment 8 Jürg Billeter 2010-10-13 20:19:13 UTC
commit 46fece1d814e59bb1443697fda41132a93bc4978
Author: Jürg Billeter <j@bitron.ch>
Date:   Wed Oct 13 22:17:41 2010 +0200

    Add suport for local constants
    
    Fixes bug 530623.