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 602511 - if ( element in array ) would be a nice addition
if ( element in array ) would be a nice addition
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.7.x
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
: 605157 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-11-20 16:34 UTC by Michael 'Mickey' Lauer
Modified: 2010-03-26 19:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Adds support for writing if (element in array) (4.85 KB, patch)
2010-01-20 05:00 UTC, Robin Sonefors (ozamosi)
needs-work Details | Review
Updated version (6.26 KB, patch)
2010-02-08 22:23 UTC, Robin Sonefors (ozamosi)
none Details | Review

Description Michael 'Mickey' Lauer 2009-11-20 16:34:09 UTC
Rather than having to use
...
bool found = false;
for ( var i = 0; i < array.length )
{
    if ( array[i] == element )
        found = true;
}
...

I tried to add a generic function that does it for me, but that seems to trigger another bug.
Comment 1 Robin Sonefors (ozamosi) 2010-01-20 05:00:15 UTC
Created attachment 151811 [details] [review]
Adds support for writing if (element in array)
Comment 2 Michael 'Mickey' Lauer 2010-02-01 02:04:54 UTC
Awesome, thanks for the patch. Seems to work fine. Jürg?
Comment 3 Jürg Billeter 2010-02-04 18:16:34 UTC
Thanks for the patch. While it works fine for, e.g., integer arrays, this fails for string arrays (and probably also for struct arrays). We should fix that before applying this to master as this would generate invalid code without any warnings at compile-time otherwise.

There is another bug in the patch but that's easy to fix: in the patch get_array_size_cexpression is used where get_array_length_cexpression should have been usd.
Comment 4 Robin Sonefors (ozamosi) 2010-02-08 22:23:08 UTC
Created attachment 153295 [details] [review]
Updated version

This version fixes the problems described above.

Also gives a user doing this with incompatible types a less nonsensical error message.
Comment 5 Jürg Billeter 2010-02-11 20:41:11 UTC
commit d962523d21b0a7de631d128d224e5fa8588a4c14
Author: Robin Sonefors <ozamosi@flukkost.nu>
Date:   Wed Jan 20 05:41:32 2010 +0100

    Support `in' operator for arrays
    
    This is already supported for some non-array types, so this patch
    merely extends it.
    
    Fixes bug 602511.
Comment 6 Jürg Billeter 2010-03-26 19:20:47 UTC
*** Bug 605157 has been marked as a duplicate of this bug. ***