Comment #0 by destructionator — 2016-04-07T01:52:54Z
When the compiler generates a RangeError, it does not tell what the index that was out of bounds happened to be. This information is available to the compiler and trivial to pass to the RangeError object, but it gets lost, wasting a LOT of time. It is my #1 annoyance with D!
I tried to implement this in dmd and I got assert errors, but I imagine it would be trivial for someone who actually knows how the e2ir.c file works - and it would mean a lot to me.
I want it to pass the index and length of the array to the _d_arraybounds function o druntime can add it to the error object.
@dkorpel updated dlang/dmd pull request #12871 "Add informative range errors for arrays" fixing this issue:
- Fix issue 15889 - Array bounds check should report index and length
Add changelog entry for RangeError with context
Use new druntime calls for range errors with context
https://github.com/dlang/dmd/pull/12871
Comment #3 by dlang-bot — 2021-08-03T00:29:16Z
dlang/dmd pull request #12871 "Fix issue 15889 - Array bounds check should report index and length" was merged into master:
- d8cc8895809da775e58e80bbb7d721a92e7833b8 by dkorpel:
Fix issue 15889 - Array bounds check should report index and length
https://github.com/dlang/dmd/pull/12871
Comment #4 by mipri — 2021-11-04T01:33:54Z
The new error message has an absurd case:
```d
unittest {
string s1 = "hi";
char[5] s2;
s2 = s1;
}
```
[email protected](4): index [2] exceeds array of length 5