From f05dd0091831c80dfe3e280d5817ab05c70ff543 Mon Sep 17 00:00:00 2001 From: Julien Fischer Date: Fri, 27 Feb 2026 20:16:56 +1100 Subject: [PATCH] Fix an incorrect error message in an exception. library/version_array2d.m: The row or column out of bounds messages are off by one; fix that. tests/hard_coded/version_array2d_test.exp: Conform to the above change. --- library/version_array2d.m | 4 ++-- tests/hard_coded/version_array2d_test.exp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/version_array2d.m b/library/version_array2d.m index 09f41ce76..65b097091 100644 --- a/library/version_array2d.m +++ b/library/version_array2d.m @@ -425,14 +425,14 @@ unsafe_rewind(version_array2d(NumRows, NumColumns, VersionArray)) = :- pred out_of_bounds_error(string::in, string::in, int::in, int::in) is erroneous. -out_of_bounds_error(PredName, RowOrColumn, Index, Max) :- +out_of_bounds_error(PredName, RowOrColumn, Index, NumRowsOrColumns) :- % Note: we deliberately do not include the array element type name in the % error message here, for performance reasons: using the type name could % prevent the compiler from optimizing away the construction of the % type_info in the caller, because it would prevent unused argument % elimination. string.format("%s: %s index %d not in range [0, %d]", - [s(PredName), s(RowOrColumn), i(Index), i(Max)], Msg), + [s(PredName), s(RowOrColumn), i(Index), i(NumRowsOrColumns - 1)], Msg), throw(index_out_of_bounds(Msg)). %---------------------------------------------------------------------------% diff --git a/tests/hard_coded/version_array2d_test.exp b/tests/hard_coded/version_array2d_test.exp index 39a1b77b3..cc9177168 100644 --- a/tests/hard_coded/version_array2d_test.exp +++ b/tests/hard_coded/version_array2d_test.exp @@ -64,16 +64,16 @@ misshapen init: found exception as expected: software_error("function `version_array2d.version_array2d\'/1: non-rectangular list of lists") out-of-bounds test 1: found exception as expected: -index_out_of_bounds("version_array2d.lookup: column index -1 not in range [0, 4]") +index_out_of_bounds("version_array2d.lookup: column index -1 not in range [0, 3]") out-of-bounds test 2: found exception as expected: -index_out_of_bounds("version_array2d.set: column index -1 not in range [0, 4]") +index_out_of_bounds("version_array2d.set: column index -1 not in range [0, 3]") out-of-bounds test 3: found exception as expected: -index_out_of_bounds("version_array2d.uset: column index 9 not in range [0, 4]") +index_out_of_bounds("version_array2d.uset: column index 9 not in range [0, 3]") out-of-bounds test 4: found exception as expected: -index_out_of_bounds("version_array2d.lookup: row index -1 not in range [0, 4]") +index_out_of_bounds("version_array2d.lookup: row index -1 not in range [0, 3]") out-of-bounds test 5: found exception as expected: -index_out_of_bounds("version_array2d.ulookup: row index 4 not in range [0, 4]") +index_out_of_bounds("version_array2d.ulookup: row index 4 not in range [0, 3]")