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 644245 - Reverse string slice cannot handle final character
Reverse string slice cannot handle final character
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Basic Types
unspecified
Other All
: Normal enhancement
: ---
Assigned To: Michael 'Mickey' Lauer
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-03-08 21:52 UTC by Rikard Nordgren
Modified: 2018-05-22 13:58 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Rikard Nordgren 2011-03-08 21:52:41 UTC
This short program compiles but gives a runtime error:

public static int main (string[] args)
{
	string s = "Testing";

	string slice = s[-3:0];
	stdout.printf(slice + "\n");

	return 0;
}

Error:
** (process:5817): CRITICAL **: string_slice: assertion `start <= end' failed


I expected this program to output "ing".
Comment 1 Michael 'Mickey' Lauer 2018-02-26 15:33:23 UTC
With the current version, string slicing always requires slicing from "left" to "right", i.e. the left parameter needs to be smaller than the right parameter. Since negative values are just a shorthand for length-<value>, this gets translated into s[4:0], which then triggers the run-time assertion.

As such, I will flag this as ENHANCEMENT now, since I think we should either make it work (perhaps, special casing the '0' in order to avoid unrecognized errors), or (even better) fully implement the Python syntax here, which is:

>>> x="Testing"
>>> x[-3:]
'ing'

With this syntax in place, it's actually ok to have the run-time assertion. Python does it similarly:

>>> x[-3:0]
''
Comment 2 GNOME Infrastructure Team 2018-05-22 13:58:00 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/179.