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 569259 - can't initialize top-level array
can't initialize top-level array
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Documentation
0.5.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-01-26 23:12 UTC by Adam Dingle
Modified: 2014-08-23 17:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Report error on non-constant field initializer in namespace (896 bytes, patch)
2013-04-01 16:31 UTC, Simon Werbeck
committed Details | Review

Description Adam Dingle 2009-01-26 23:12:51 UTC
When I try to compile this program:

==== test.vala ===
int[] a = { 1, 2, 3};

int main() { return a[0]; }
=== end ===

I get the following error:

test.vala:1.1-1.7: error: Non-constant field initializers not supported in this context
int[] a = { 1, 2, 3};
^^^^^^^

But the program works fine if I either (a) declare the array to be of type const int[], or (b) omit the initializer.

This is a bug, right?
Comment 1 Chris Van Vranken 2009-06-06 11:21:40 UTC
This can be prevented if you place the array being initialized within a class.  If it is outside of main and not in a class then one gets this message. (Vala 0.7.3)
Comment 2 Michael 'Mickey' Lauer 2009-10-08 12:40:12 UTC
Thanks for your report. As Chris correctly replies, your code is invalid, since in the top level context only constant initializers are supported.
Comment 3 Adam Dingle 2009-10-08 13:06:10 UTC
It's fine if only constant initializers are supported in the top-level context, but that fact is currently undocumented: it should be mentioned in the Vala Reference Manual somewhere in the Expressions section (http://www.vala-project.org/doc/vala-draft/expressions.html) and/or in the Vala Tutorial in the "Arrays" section (http://live.gnome.org/Vala/Tutorial#head-4b9d97902aa200e69617514a45e01f014421d67e).  So I'm reopening this until the documentation is fixed.  If there's some other place I should be reporting documentation bugs instead then please let me know.
Comment 4 pancake 2013-02-18 00:05:59 UTC
Still not fixed in 2013...
```
** (valac:10077): CRITICAL **: vala_ccode_function_add_declaration: assertion `self != NULL' failed

** (valac:10077): CRITICAL **: vala_ccode_function_add_assignment: assertion `self != NULL' failed

** (valac:10077): CRITICAL **: vala_ccode_function_add_assignment: assertion `self != NULL' failed

** (valac:10077): CRITICAL **: vala_ccode_function_add_assignment: assertion `self != NULL' failed

** (valac:10077): CRITICAL **: vala_ccode_function_add_assignment: assertion `self != NULL' failed
a.vala:1.1-1.7: error: Non-constant field initializers not supported in this context
int[] a = { 1, 2, 3};
^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
```
Comment 5 Simon Werbeck 2013-04-01 16:31:23 UTC
Created attachment 240317 [details] [review]
Report error on non-constant field initializer in namespace

Fixes bug 569259
Comment 6 Jürg Billeter 2014-08-23 17:54:24 UTC
commit 1b3b48aa7e8b550643499bf842c0ca92056aa520
Author: Simon Werbeck <simon.werbeck@gmail.com>
Date:   Mon Apr 1 05:00:12 2013 +0200

    Error on non-const field initializer in namespace
    
    Fixes bug 569259