From 8195fbed4a8067362656d38e56fec3c4eb3deef1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 24 Jan 2019 22:48:37 -0800 Subject: lib: revise wording of integer range errors. * arith.c (c_unum): Fix misleading error message, and instead specify the range that was violated. * lib.c (c_num): Similar change: don't refer to a 'cnum range' which means nothing to the user. --- arith.c | 3 ++- lib.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/arith.c b/arith.c index bd66bfbc..8bc459ca 100644 --- a/arith.c +++ b/arith.c @@ -213,7 +213,8 @@ ucnum c_unum(val num) } /* fallthrough */ range: - uw_throwf(error_s, lit("~s given, non-negative expected"), num, nao); + uw_throwf(error_s, lit("~s is out of allowed range [0, ~a]"), + num, unum(UINT_PTR_MAX), nao); default: type_mismatch(lit("~s is not an integer"), num, nao); } diff --git a/lib.c b/lib.c index 925bf638..26806b41 100644 --- a/lib.c +++ b/lib.c @@ -3099,20 +3099,21 @@ val num(cnum n) return bignum(n); } -cnum c_num(val num) +cnum c_num(val n) { - switch (type(num)) { + switch (type(n)) { case CHR: case NUM: - return coerce(cnum, num) >> TAG_SHIFT; + return coerce(cnum, n) >> TAG_SHIFT; case BGNUM: - if (in_int_ptr_range(num)) { + if (in_int_ptr_range(n)) { int_ptr_t out; - mp_get_intptr(mp(num), &out); + mp_get_intptr(mp(n), &out); return out; } - uw_throwf(error_s, lit("~s is out of cnum range"), num, nao); + uw_throwf(error_s, lit("~s is out of allowed range [~s, ~s]"), + n, num(INT_PTR_MIN), num(INT_PTR_MAX), nao); default: - type_mismatch(lit("~s is not an integer"), num, nao); + type_mismatch(lit("~s is not an integer"), n, nao); } } -- cgit v1.2.3