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 741491 - Const struct array fields cannot be initialized
Const struct array fields cannot be initialized
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Structs
unspecified
Other All
: High normal
: 1.0
Assigned To: Vala maintainers
Vala maintainers
: 597817 670248 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-12-13 21:34 UTC by pancake
Modified: 2018-05-22 15:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Example of failing code (142 bytes, text/x-vala)
2015-07-24 13:43 UTC, Steef Hegeman
Details

Description pancake 2014-12-13 21:34:50 UTC
Maybe i'm doing something wrong, but i can't find any way to do this in Vala.

This is the test:

```
struct Foo {
        public string name;
        public string title;
        public int[] ages;
}

const Foo foo = {
        name: "Hello",
        title: "World",
        ages: { 1,2,3 }
};

void main() {
        print ("%s\n", foo.ages[1]);
}
```
Comment 1 Steef Hegeman 2015-07-24 13:43:16 UTC
Created attachment 308080 [details]
Example of failing code

Results in following compiler error:
ERROR:valaccodearraymodule.c:1108:vala_ccode_array_module_real_get_array_length_cvalue: assertion failed: (size != null && size.size >= dim)
Comment 2 Steef Hegeman 2015-07-24 13:48:50 UTC
To further specify what this is about: the compiler currently fails when attempting to initialize an array in a const struct inline.

Relevant discussion:
https://mail.gnome.org/archives/vala-list/2015-July/msg00010.html

Like Al Thomas mentioned, it seems like the compiler could either give a warning or the inline initialization could be implemented.

I'm not exactly sure whether this is considered valid Vala code in the first place though.

Sorry for the double post
Comment 3 Luca Bruno 2015-08-20 12:58:55 UTC
Vala should emit an error, because that array is supposed to be heap-allocated, hence it's not possible in a const context.

In a const context you should explictly tell vala (and C) that array is an inline array of 3 elements, like int ages[3];
Comment 4 Rico Tzschichholz 2017-03-09 21:42:07 UTC
*** Bug 597817 has been marked as a duplicate of this bug. ***
Comment 5 Rico Tzschichholz 2017-03-09 21:53:28 UTC
*** Bug 670248 has been marked as a duplicate of this bug. ***
Comment 6 GNOME Infrastructure Team 2018-05-22 15:20:45 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/486.