Skip to content

fix(builtins): four silent-wrong-answer contracts — min/max N-ary, predicate type-rejection, negative indices, directory SIGABRT (#312, #314, #316, #317)#454

Merged
InauguralPhysicist merged 1 commit into
mainfrom
claude/refer-to-hq-mb177l
Jul 6, 2026
Merged

fix(builtins): four silent-wrong-answer contracts — min/max N-ary, predicate type-rejection, negative indices, directory SIGABRT (#312, #314, #316, #317)#454
InauguralPhysicist merged 1 commit into
mainfrom
claude/refer-to-hq-mb177l

Conversation

@InauguralPhysicist

Copy link
Copy Markdown
Collaborator

What does this PR do?

Batch-fixes the four good-first-issue correctness bugs surfaced by the 2026-07 backlog triage — all silent wrong answers or a first-touch crash, so they outrank the #419 feature queue (correctness before performance, first-run success before advanced features). All four live in src/builtins.c.

Tests: new tests/test_builtin_contracts.eigs (33 asserts) registered as suite section [105] via check_eigs_suite, plus a shell check that a directory arg exits 1 with the clean error. CA4 in test_string_math.eigs updated — it codified the old char_at negative-index bug.

Gates: release suite 2536/2536; make asan + ASAN_OPTIONS=detect_leaks=1 2536/2536 with leak tally 0; doc-examples [89]/[90] and stdlib-discoverability [99b] green.

Checklist

  • make test passes locally
  • New builtins have signature comments and docs in docs/BUILTINS.md (no new builtins; changed rows updated)
  • New library functions follow conventions in docs/STDLIB.md (n/a — no new library functions)
  • New examples have a comment header explaining what they demonstrate (n/a — no new examples)
  • CHANGELOG.md updated (if user-facing change)

Closes #312. Closes #314. Closes #316. Closes #317.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BoHJFSkaaB2H1dvcdW2ibs


Generated by Claude Code

…edicate type-rejection, negative indices, directory SIGABRT (#312, #314, #316, #317)

Batch fix from the 2026-07 backlog triage — all four are silent wrong
answers or a first-touch crash, so they outrank the #419 feature queue
(correctness before performance, first-run success before features):

- #317 min/max: true N-ary reductions over a flat numeric list. The old
  code read only items[0..1] — `max of [1, 2, 3]` returned 2 (worse than
  the issue reported) — and `min of [5]` returned 0. A bare number now
  returns itself (mirrors sum); empty/non-numeric lists keep the 0
  fallback.
- #316 string predicates: index_of/contains/starts_with/ends_with reject
  non-string operands (miss: -1 / 0) instead of folding them to "" and
  spuriously matching everything (index_of returned 0, "found at index
  0", violating its documented "or -1" contract).
- #312 get_at/set_at/char_at: negative indices count from the end,
  matching the [] operator's documented semantics, including the 2-D
  row/col paths. Out-of-range keeps each builtin's old miss default.
- #314 read_file_util: reject non-regular files up front — fopen
  succeeds on a directory and ftell reports LONG_MAX, which sailed into
  xmalloc's fatal-OOM abort (exit 134). A directory script arg now takes
  the clean "cannot read file" path (exit 1); covers load_file and
  --fmt/--lint too.

Tests: new tests/test_builtin_contracts.eigs (33 asserts, suite section
[105] via check_eigs_suite) + a shell check that a directory arg exits 1;
CA4 in test_string_math.eigs updated — it codified the old char_at bug.
Docs: BUILTINS.md rows updated; SPEC/COMPARISON untouched (negative
indexing was already the documented semantics — the builtins now conform).

Gates: release suite 2536/2536; make asan + detect_leaks=1 2536/2536,
leak tally 0.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BoHJFSkaaB2H1dvcdW2ibs
@InauguralPhysicist InauguralPhysicist merged commit 4c9f044 into main Jul 6, 2026
17 checks passed
@InauguralPhysicist InauguralPhysicist deleted the claude/refer-to-hq-mb177l branch July 6, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment