Skip to content

fix: emit runtime error for array.reduce on empty array with no initial value#289

Merged
cs01 merged 1 commit intomainfrom
fix/array-reduce-empty-guard
Mar 12, 2026
Merged

fix: emit runtime error for array.reduce on empty array with no initial value#289
cs01 merged 1 commit intomainfrom
fix/array-reduce-empty-guard

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 12, 2026

Summary

  • [1,2,3].reduce(fn) (no initial value) on an empty array previously read uninitialized memory (segfault/UB). Now emits a clear runtime error: Error: reduce of empty array with no initial value and exits with code 1 — matching V8/Node behavior.
  • Guards added to both numeric and string array reduce paths.

Test plan

  • New fixture array-reduce-empty.ts asserts exit code 1
  • Existing array-reduce.ts (with initial value + non-empty no-init) still passes
  • npm run verify:quick passes (tests + Stage 1 self-hosting)

@cs01 cs01 merged commit e793055 into main Mar 12, 2026
12 checks passed
@cs01 cs01 deleted the fix/array-reduce-empty-guard branch March 19, 2026 05:23
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