Skip to content

fix(compiler): return unmatched values from maybe without else - #103

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/9b519c17
Dec 1, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/9b519c17

Conversation

@mremond

@mremond mremond commented Dec 1, 2026

Copy link
Copy Markdown
Member

Why

When `?=` could not match a value in a `maybe` block without `else`, Nera raised an error instead of returning that value.

What changed

  • The block now returns the unmatched value and skips the rest of the block.
  • Successful matches and blocks with `else` behave as before.

Before and after

Before: Nera raised `else_clause` in both tested positions, while the standard Erlang runtime, BEAM, returned `{error,e}` from the block.

After: Both `maybe` blocks now return `{error,e}`, and all three tested results match BEAM.

This changes what compiled programs return, not what appears on screen.

Checked

Live validation: Demonstrated for this version. 2 of 2 scenarios driven live in the product.

Scenario Result Evidence
Use a failed match as a function result and inside `try`. ✅ Passed live Nera now matches BEAM OTP 27.3.4.6 in both positions and when the match succeeds.
Run the same test on Nera and the standard Erlang runtime. ✅ Passed live The old native compiler failed at the first mismatch. The fixed version and BEAM each passed ten runs.
  • Local Linux checks: The release build, Clippy, allocator and stacktrace checks passed, along with 2,301 Rust and 553 native tests.
  • Independent review: Independent reviews found no issues in the code or the recorded native and BEAM results.
How it was checked

Built and ran the same three-case program on unchanged native Nera, fixed native Nera and BEAM. The fixed native output matches BEAM byte for byte.

Ran the shared fixture with `nera test maybe_without_else -j 1 --timeout 30` and with `erlc` followed by `maybe_without_else:test/0` on BEAM.

Ran the pinned, locked release build, Clippy with warnings denied, the workspace suite, allocator and stacktrace checks, and `nera test -j 1 --timeout 30`.

Risk

Risk: low in every dimension.

Full risk assessment
Dimension Level Why
Blast radius low Only the mismatch path of maybe blocks without else changes.
Behavior low Returns the unmatched value as Erlang specifies instead of raising.
Undo low A revert restores the old compiler behavior without data changes.
Evidence low Native program output and a shared regression were compared with BEAM.
Sensitivity low No sign-ins, persisted data, or sensitive runtime operations change.
Novelty low Uses the existing return and value-join instructions.
Dependencies low No dependency changes.
Not done

The local run ignored one Rust test and skipped two native tests that require external OneCached modules.

GitHub runs the hosted checks on the combined pull request after approval.

The block now returns the unmatched value and skips the rest of the block.

Successful matches and blocks with `else` behave as before.
@mremond
mremond merged commit eae880d into main Dec 1, 2026
2 checks passed
@mremond
mremond deleted the infinitary-batch/9b519c17 branch December 1, 2026 18:38
@github-actions github-actions Bot added this to the 0.1.1 milestone Dec 1, 2026
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