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 663251 - x[i]++ doesn't work with GenericArray
x[i]++ doesn't work with GenericArray
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: general
0.14.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 662198 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-11-02 16:58 UTC by Siegfried Gevatter (RainCT)
Modified: 2018-05-22 14:12 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Siegfried Gevatter (RainCT) 2011-11-02 16:58:33 UTC
[rainct, tmp]$ cat foo.vala 
public void main(string[] args)
{
    var arr = new GenericArray<int> ();
    arr.length = 3;
    arr[0] = 1;
    arr[1] = 2;
    arr[2] = 3;

    arr[1]++;
}
[rainct, tmp]$ valac foo.vala 
foo.vala:9.5-9.10: error: The expression `GLib.GenericArray<int>' does not denote an array
    arr[1]++;
    ^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
Comment 1 Siegfried Gevatter (RainCT) 2011-11-03 13:53:58 UTC
Furthermore, the syntax "arr[x] += 1" compiles but results in an incorrect value.
Comment 2 Michael 'Mickey' Lauer 2018-02-21 13:25:20 UTC
*** Bug 662198 has been marked as a duplicate of this bug. ***
Comment 3 Al Thomas 2018-02-21 15:38:20 UTC
GenericArray is a binding to GLib's GPtrArray (https://developer.gnome.org/glib/stable/glib-Pointer-Arrays.html). It is an array of pointers to any data type. Vala resrticts the data type to that given at construction time by the type parameter using SimpleGenerics. For the example above it is int.

It doesn't make sense to increment an item in the array because that is a pointer and not a value. So the 'does not denote an array' error makes some sense. Ideally GPtrArray would have a replace function, but updating can be done with dereferencing the pointer and updating the value or using remove_index() and insert().

Also int is a value type, not a reference type(pointer), so it should be boxed for GenericArray.
Comment 4 GNOME Infrastructure Team 2018-05-22 14:12:10 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/243.