String slices s[..0] and s[0..0] return an empty string rather than s[0].
Source Code:
var s = 'string indexing is "fun"';
// These should all be true
writeln(s[0] == s[..0]); // false
writeln(s[0] == s[0..0]); // false
// Some other checks
writeln(s[0..1] == s[..1]); // true
writeln(s[1] == s[1..1]); // true
writeln(s[1] == s[1..1]); // true
writeln(s[..5] == s[0..5]); // true
writeln(s[2..2] == s[2]); // true
// Sanity check to confirm it's only strings
var A = [1,2,3,4];
writeln(A[0] == A[..0]); // true
writeln(A[0] == A[0..0]); // true
chpl --version: chpl version 1.23.0 pre-release (dcb3f0e574)Thanks @cassella for helping identify this one.
To be even more precise, s[..0] and s[0..0] are returning empty strings where they should be returning s.
Happily, these same failures do not seem to occur in the bytes type.
This was discovered in, and the cause of, #15522.
There may be a quick fix based on the 0 vs 1-based indexing changes. But the potentially responsible part of the string implementation is problematic in different respects. I hope to resolve this as part of a refactor of that code as early as next week.
I just checked that, changing
1445: if cp_high > 0 {
to
1445: if cp_high >= 0 {
works.
Thanks @ram-nad, that's the quick fix that I was suspecting. I am hoping to make bigger changes to that code starting today or tomorrow, your observation will help :)
A note so we don't forget -- the following work-around in mason can be reverted when this is fixed:
https://github.com/chapel-lang/chapel/pull/15529/files#diff-71a91c1fdf3c3d0e5a204b343fafd8d6R89
Most helpful comment
A note so we don't forget -- the following work-around in mason can be reverted when this is fixed:
https://github.com/chapel-lang/chapel/pull/15529/files#diff-71a91c1fdf3c3d0e5a204b343fafd8d6R89