GNOME Bugzilla – Bug 644245
Reverse string slice cannot handle final character
Last modified: 2018-05-22 13:58:00 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".
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] ''
-- 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.