#271 Sequence out-of-bounds returns instead of signaling: elt/subseq don't error on bad bounds

closed
Opened by atgreen

Split-independent conformance bugs (CLHS: out-of-bounds index/bounding indices must signal an error, usually type-error). Found probing crash-robustness (2026-07-10):

(elt (list (quote a) (quote b)) 9) => NIL ; should signal (index out of bounds) (subseq (list (quote a) (quote b) (quote c)) 5) => NIL ; start > length, should error (subseq "abc" 1 9) => "bc" ; end > length, should error (truncates instead)

By contrast funcl is otherwise crash-robust here: nth/svref/char/aref/symbol-name/symbol-value/nreverse all correctly signal type-errors on bad TYPE, and aref/char signal index-out-of-bounds on a vector/string. The gap is the LIST path of elt/subseq (nthcdr-walks off the end and returns NIL/car-of-nil instead of a bounds error) and string subseq end-clamping.

LOW severity (wrong result, not a crash). CAUTION before fixing: elt/subseq are widely used internally; adding a strict bounds-signal could regress callers that rely on the lenient NIL/clamp behavior — audit callers first. Their ansi-test .error variants are currently ALSO blocked by the fixture handler-case recursion (cave#269), so fixing wont flip harness tests until ADR-0026 package shadowing lands. Filed for when that unblocks.

Comments (1)

atgreen3992785626

FIXED in stdlib (commit follows in today's batch): elt and subseq bounds-check against (length seq) and signal a type-error per CLHS. Probes: (elt '(1 2) 9) => signals; (elt "ab" -1) => signals; (subseq "abc" 1 9) => signals; in-bounds behavior unchanged ((subseq "abcd" 1 3) => "bc").