Skip to content

fix(parser): accept throw as the function name of a fun reference - #111

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/81ba3ed9
Dec 5, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/81ba3ed9

Conversation

@mremond

@mremond mremond commented Dec 5, 2026

Copy link
Copy Markdown
Member

Why

Code written for BEAM may pass `fun erlang:throw/1` like any other function, and erlc builds it, but Nera rejected it with "unexpected token ... found 'throw'".

What changed

  • `fun erlang:throw/1` and `fun M:throw/1` build natively, and calling the fun throws its argument, as on BEAM.
  • Functions named `true` and `false` can be referenced the same way; reserved words such as `maybe` are still rejected, as erlc does.
  • A new `throw_fun_ref` fixture checks this natively and on BEAM.

Before and after

Before: A module containing `F = fun erlang:throw/1, F(x)` failed to build natively; only the quoted form `fun erlang:'throw'/1` built.

After: Both forms build, and `catch F(x)` returns `x` natively, as on BEAM OTP 29; the new fixture passes 20 of 20 native runs and 10 of 10 on BEAM.

A compiler change: nothing on screen changes; the evidence is build and run output.

Checked

  • Untouched build on the base version: `fun erlang:throw/1` failed with "unexpected token ... found 'throw'"; the fixture failed to compile; the quoted form already built and printed x
  • Fixed build, the same probes: Plain and quoted forms print x; functions named true and false are callable through fun references; `fun m:maybe/1` is still rejected, as erlc rejects it
  • Fixture `throw_fun_ref` repeated: 10 of 10 with the default scheduler count, 10 of 10 with one scheduler, 10 of 10 on BEAM OTP 29
  • Local CI commands: Release builds, clippy with warnings denied, the workspace tests (2306 passed, 1 ignored), the allocator check and the stacktrace order check all passed
  • End-to-end suite, one job at a time: 563 passed, 2 skipped because they need external onecached modules
How it was checked

cargo build --release --locked -p nera-runtime && cargo build --release --locked

cargo clippy --workspace --all-targets --locked -- -D warnings

cargo test --workspace --locked --no-fail-fast

python3 scripts/test-allocator-config.py

./target/release/nera test -j 1 --timeout 30

python3 scripts/test-stacktrace-order.py

erlc tests/throw_fun_ref.erl and throw_fun_ref:test() on OTP 29, 10 runs

Risk

Risk: low in every dimension.

Full risk assessment
Dimension Level Why
Blast radius low One match arm in the fun reference parser
Behavior low A form erlc accepts now builds instead of failing
Undo low Revert the commit
Evidence low Failure reproduced before, fixture and full local suite pass after, also on BEAM
Sensitivity low No saved data, settings or credentials
Novelty low Reuses the existing keyword-name helper the module part already uses
Dependencies low No dependency change
Not done

Hosted CI runs only on pull requests and main, so this branch has none of its own; the batch pull request runs it.

`fun erlang:throw/1` and `fun M:throw/1` build natively, and calling the fun throws its argument, as on BEAM.

Functions named `true` and `false` can be referenced the same way; reserved words such as `maybe` are still rejected, as erlc does.

A new `throw_fun_ref` fixture checks this natively and on BEAM.
@mremond
mremond merged commit f1b581f into main Dec 5, 2026
1 check passed
@mremond
mremond deleted the infinitary-batch/81ba3ed9 branch December 5, 2026 12:19
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