Bug 15889 – Array bounds check should report index and length

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-04-07T01:52:54Z
Last change time
2021-11-09T14:50:44Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Adam D. Ruppe
See also
https://issues.dlang.org/show_bug.cgi?id=5547

Comments

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.
Comment #1 by dfj1esp02 — 2016-06-10T17:03:17Z
Comment #2 by dlang-bot — 2021-07-14T09:47:20Z
@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
Comment #5 by dkorpel — 2021-11-04T09:00:17Z
Comment #6 by dkorpel — 2021-11-04T09:38:47Z
PR to put the fix in stable: https://github.com/dlang/dmd/pull/13265
Comment #7 by dkorpel — 2021-11-09T14:50:44Z
Now merged to stable. If you need better error messages for out of bounds slice copy, please open a new enhancement request.