Skip to content

fix(codegen): Err stores its payload at .value, like every other variant - #791

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/err-payload-value
Nov 14, 2026
Merged

hyperpolymath merged 1 commit into
mainfrom
fix/err-payload-value

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

In the Bun/JS, plain-JS and Lua backends, an Err(m) match arm bound m to undefined (nil in Lua). The runtime preludes built Err as { tag, error }, but every match lowering reads a single-payload constructor at .value, as Ok and Some use. Any program that carried an error message through Result printed undefined.

Found while writing kyX (metadatastician/kyx), the estate's A2ML→deed projection compiler, which reports fail-closed errors as Err strings.

Changes

  • lib/codegen_deno.ml, lib/js_codegen.ml, lib/lua_codegen.ml: Err stores value. Nothing in the repo reads .error.
  • tests/codegen-bun/result_payload.{affine,harness.mjs}: new regression test. It binds the Err payload directly and inside Some(Err(m)).
  • tools/run_codegen_bun_tests.sh: compiles each harness's own subject, not just host_profile, so new Bun harnesses actually run.

Testing

  • tools/run_codegen_bun_tests.sh: the new harness fails before the fix (got undefined) and passes after (2 harnesses green).
  • dune runtest: all 570 alcotest cases pass. The res-to-affine walker suites fail identically on unmodified main in this environment, so they are unrelated.
  • Lua: changed for consistency only. Not executed here (no Lua interpreter available).

Generated by Claude Code

The Bun/JS, plain-JS and Lua runtime preludes built Err as { tag, error },
but every match lowering reads a single-payload constructor at `.value`
(gen_pattern_test / gen_pattern_bindings in all three backends). So an
`Err(m)` arm bound `m` to undefined (nil in Lua): any program that reported
an error message through Result printed "undefined". Found while writing
kyX (metadatastician/kyx), whose fail-closed errors travel as Err strings.

Fixed at the source: the three preludes now build Err with `value`, the
same field Ok and Some use. Nothing in the repo reads `.error`.

Test: tests/codegen-bun/result_payload.{affine,harness.mjs} binds the Err
payload directly and inside a nested Some(Err(m)) pattern. It fails before
this change and passes after. tools/run_codegen_bun_tests.sh now compiles
each harness's own subject, not only host_profile, so new Bun harnesses
are actually exercised. The Lua backend is changed for consistency but not
run here (no Lua interpreter in this environment).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZnvMV5Ghe7LUf3oc6N
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 14, 2026 20:27
@hyperpolymath
hyperpolymath merged commit fbe4d2c into main Nov 14, 2026
8 of 9 checks passed
@hyperpolymath
hyperpolymath deleted the fix/err-payload-value branch November 14, 2026 20:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T20:29:28.283046Z 585db95 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-14T20:30:59.493344Z 585db95 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

2 participants