From ea3a4203fa06ba9d60e0796d66f35222bd08fcd7 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 6 Jan 2025 01:10:36 +0800 Subject: [PATCH] fixes #24599; misleading error message with large array bounds (#24601) fixes #24599 (cherry picked from commit aeeccee50a603c37c94ee3aa0c3d109654814654) --- compiler/semtypes.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 4855faf736..5f33df5c7d 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -409,8 +409,12 @@ proc semArrayIndex(c: PContext, n: PNode): PType = result = makeRangeWithStaticExpr(c, e.typ.n) elif e.kind in {nkIntLit..nkUInt64Lit}: if e.intVal < 0: - localError(c.config, n.info, - "Array length can't be negative, but was " & $e.intVal) + if e.kind in {nkIntLit..nkInt64Lit}: + localError(c.config, n.info, + "Array length can't be negative, but was " & $e.intVal) + else: + localError(c.config, n.info, + "Array length can't exceed its maximum value (9223372036854775807), but was " & $cast[BiggestUInt](e.intVal)) result = makeRangeType(c, 0, e.intVal-1, n.info, e.typ) elif e.kind == nkSym and (e.typ.kind == tyStatic or e.typ.kind == tyTypeDesc): if e.typ.kind == tyStatic: