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 641267 - ValaCCodeArrayModule, support for zero/negative slice values in arrays.
ValaCCodeArrayModule, support for zero/negative slice values in arrays.
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Arrays
0.11.x
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on: 641268
Blocks:
 
 
Reported: 2011-02-02 17:16 UTC by Marco Trevisan (Treviño)
Modified: 2018-05-22 13:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
valaccode: ArrayModule, support for negative slice values in arrays. (3.15 KB, patch)
2011-02-02 17:16 UTC, Marco Trevisan (Treviño)
none Details | Review

Description Marco Trevisan (Treviño) 2011-02-02 17:16:12 UTC
Created attachment 179905 [details] [review]
valaccode: ArrayModule, support for negative slice values in arrays.

This patch allows to perform slices on arrays using negative indexes, as supported by string slice function.

I.e.:
	int[] a = { 42, 23, 11 };
	int[] b = a[-2:0]; //23, 11
	int[] c = a[-2:-1]; // 23

This implementation doesn't shows errors when the slice values aren't valid, in some cases (with too great negative inputs) it just don't slice the array, also if I think that would be better to add more checks in the generated code (maybe asserts when no IntegerLiteral's are used) when start/stop slice indexes aren't well formed.
Comments about this are welcome!

It also add the support for zero-end slice value, so
	int[] b = a[1:0] // creates an array with all the values but the first
	int[] b = a[-1:0] // creates an array with just the latest value
Comment 1 Fabian Deutsch 2011-03-04 21:44:20 UTC
Hey, I do not know if this will be fixed with the above patch or if it is a different problem. The following snippet does not work:

void main()
{
	string[] arr = {"Hello", "World", "!"};
	debug (string.joinv(" ", arr[0:1])); // Does not work as expected
	string[] arr2 = arr[0:1];
	debug (string.joinv(" ", arr2)); // Works as expected
}
Comment 2 Marco Trevisan (Treviño) 2011-03-04 22:38:26 UTC
Mh, I guess this is another issue; with the present patch I still get this output:

** (process:13066): DEBUG: array.vala:14: Hello World !
** (process:13066): DEBUG: array.vala:16: Hello
Comment 3 Michael 'Mickey' Lauer 2017-11-09 09:51:00 UTC
With Vala 0.38, I get

** Message: Untitled 2.vala:4: Hello
** Message: Untitled 2.vala:6: Hello

for your snippet, which I guess is expected.

There is still something broken in the negative slicing, i.e. I can't find any invocation that reliably gets me an array consisting of the last element only.
Comment 4 GNOME Infrastructure Team 2018-05-22 13:53:09 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/162.