Bug 7871 – RangeViolation with findSplitBefore

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-09T01:27:00Z
Last change time
2015-06-09T05:15:18Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2012-04-09T01:27:33Z
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]; }
Comment #2 by k.hara.pg — 2012-04-09T08:47:53Z
This issue is caused by fixing bug 7583. https://github.com/D-Programming-Language/dmd/pull/871
Comment #3 by github-bugzilla — 2012-04-09T13:52:15Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/88bf66c5a61c85e46a862149c519d13f6b68a194 fix Issue 7871 - RangeViolation with findSplitBefore This is a regression caused by fixing issue 7583. When you syntaxCopy() a ast sub-tree, contained lengthVar is discarded. But it is already inserted to scope symbol table. So we should share lengthVar between all copy of syntax trees instead of creating new one. https://github.com/D-Programming-Language/dmd/commit/6888809e505e3fed42089a35153702854918009d Merge pull request #871 from 9rnsr/fix7871 Issue 7871 - RangeViolation with findSplitBefore