Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 7456d96

Browse files
authored
Merge pull request #3572 from nordlow/better-range-diag
More readable message in ArrayIndexError
2 parents cbc06e0 + 87bed6c commit 7456d96

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/core/exception.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ArrayIndexError : RangeError
9797
this.length = length;
9898

9999
// Constructing the message is a bit clumsy:
100-
// It's essentially `printf("index [%zu] exceeds array of length [%zu]", index, length)`,
100+
// It's essentially `printf("index [%zu] is out of bounds for array of length [%zu]", index, length)`,
101101
// but even `snprintf` isn't `pure`.
102102
// Also string concatenation isn't `@nogc`, and casting to/from immutable isn't `@safe`
103103
import core.internal.string : unsignedToTempString;
@@ -107,7 +107,7 @@ class ArrayIndexError : RangeError
107107
sink.rangeMsgPut("index [");
108108
sink.rangeMsgPut(unsignedToTempString!10(index, tmpBuf));
109109
sink.rangeMsgPut("]");
110-
sink.rangeMsgPut(" exceeds array of length ");
110+
sink.rangeMsgPut(" is out of bounds for array of length ");
111111
sink.rangeMsgPut(unsignedToTempString!10(length, tmpBuf));
112112
this.msgBuf = buf;
113113
super(msgBuf[0..$-sink.length], file, line, next);
@@ -116,7 +116,7 @@ class ArrayIndexError : RangeError
116116

117117
@safe pure unittest
118118
{
119-
assert(new ArrayIndexError(900, 700).msg == "index [900] exceeds array of length 700");
119+
assert(new ArrayIndexError(900, 700).msg == "index [900] is out of bounds for array of length 700");
120120
// Ensure msg buffer doesn't overflow on large numbers
121121
assert(new ArrayIndexError(size_t.max, size_t.max-1).msg);
122122
}

0 commit comments

Comments
 (0)