Skip to content

add runtime bounds checking and improve array method error diagnostics#183

Merged
cs01 merged 4 commits intomainfrom
bulletproof-compiler
Mar 10, 2026
Merged

add runtime bounds checking and improve array method error diagnostics#183
cs01 merged 4 commits intomainfrom
bulletproof-compiler

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 10, 2026

Summary

  • Add runtime array bounds checking for numeric arrays and Uint8Arrays — out-of-bounds access now prints a clear error message ("Error: array index N out of bounds (length M)") and exits instead of segfaulting
  • Convert 31 throw new Error() calls to ctx.emitError() across all array method codegen — users now get proper compiler errors with file/line info instead of ugly stack traces when they misuse array methods (wrong arg count, wrong arg type for filter/map/reduce/find/some/every/etc.)
  • Add runtime helper infrastructure (__cs_bounds_check, __cs_null_check) in LLVM declarations

Notes

  • Object arrays and string arrays don't have bounds checking yet — the compiler's own code has JS-style arr[0] patterns on empty arrays that need fixing first (tracked separately)
  • Numeric array and Uint8Array bounds checking passes all 449 tests + self-hosting Stage 1

Test plan

  • New test fixture array-bounds-check.ts verifies OOB access exits with code 1
  • All existing tests pass (449 node, 448 native)
  • Self-hosting Stage 1 passes

🤖 Generated with Claude Code

@cs01 cs01 merged commit 7083969 into main Mar 10, 2026
12 checks passed
@cs01 cs01 deleted the bulletproof-compiler branch March 10, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant