More readable message in ArrayIndexError#3572
Conversation
|
Thanks for your pull request and interest in making D better, @nordlow! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + druntime#3572" |
|
Is the intention to fix the wording when the index equals the length? |
This change certainly makes for a better interpretation in that case, but I hadn't thought of that myself actually. This change is on behalf of @andralex so safest to let him answer this question aswell. |
|
Not to bikeshed but "too large" makes me think of an integer value that doesn't fit in a Can we look at what terminology / phrasing other languages do, and stick to that? Maybe just "out of bounds"? |
|
Good point. How about Index [7] is beyond the end of array of length 3. Native speakers please opine! |
Where did this come up?
That sounds equivalent to 'exceeds', which means to "go beyond what is allowed or stipulated by (a set limit)" or "go past an allowed limit". I'm not against changing the message, I'm just curious what's unclear about it. After I wrote the new array error messages I asked a programmer who doesn't program in D whether it was clear and he thought so. Is 'exceed' a word people don't know or don't expect in this context? |
|
It's not unclear, it's grammatically incorrect. An index does not exceed an array. It exceeds the length of the array. The meaning of the message is that whatever index you give must be less than the length. |
|
How about this - no repetitions, no akwardness:
Worx? |
Ah, makes sense. I originally wrote "index [20] exceeds array length 20" but I added the 'of' because it looks weird that 20 exceeds 20.
Sounds good |
|
@dkorpel thanks, and also thank you for putting in the actual work! |
|
SBCL uses: 'Invalid index 7, should be a non-negative integer below 3'. I like that because it makes it clear what's happening when the index is the array length. |
|
love it! |
|
'non-negative' is redundant in D's case, since array indices have the unsigned |
This leads to How about "Index 7 is out of bounds of range [0 .. 2]"? |
Then |
|
I'm gonna wait and see what fighter that still stands after a couple of more rounds... ;) |
|
"Index %s is out of bounds for array of length %s" is fine with me. |
dkorpel
left a comment
There was a problem hiding this comment.
Also update the comment on line 100:
It's essentially
printf("index [%zu] exceeds array of length [%zu]", index, length)
Done. |
FYI, @andralex.