This code works with 2.058
import std.algorithm;
void main()
{
enum lineStart = `<bookmark href="https://`;
string line = `<bookmark href="https://stuff">`;
auto a = findSplitBefore(line[lineStart.length .. $], `"`)[0];
}
But with the latest head, it gives
core.exception.RangeError@q(7): Range violation
----------------
./q(_d_array_bounds+0x2a) [0x43aae6]
./q() [0x4389be]
./q(_Dmain+0x39) [0x4319c9]
./q(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x17) [0x43b2ab]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x23) [0x43ac2b]
./q(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x3d) [0x43b2f9]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x23) [0x43ac2b]
./q(main+0xd3) [0x43abc3]
/lib/libc.so.6(__libc_start_main+0xf5) [0x7f907bdb9455]
I'm not sure what's causing the range violation though, since it goes away in weird ways. If you remove the [0], it works, but if I add this line after it
auto b = a[0];
it works too. If I don't slice line anymore, it also works. If I slice line like line[0 .. $] or line[$ .. $], it also works, but anything which slices only part of the string (instead of none of it or all of it) results in it failing. So, I have absolutely no clue what's going on here, but clearly something is wrong with the code being generated.
Comment #1 by k.hara.pg — 2012-04-09T08:05:32Z
Reduced test case:
----
struct Tuple
{
string field;
alias field this;
}
auto findSplitBefore(string haystack)
{
return Tuple(haystack);
}
void main()
{
string line = `<bookmark href="https://stuff">`;
auto a = findSplitBefore(line[0 .. $])[0];
}