Skip to content

fix(parser): accept catch Expr as a first call argument or tuple element - #107

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/04019581
Dec 3, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/04019581

Conversation

@mremond

@mremond mremond commented Dec 3, 2026

Copy link
Copy Markdown
Member

Why

Erlang code that passes a catch expression straight into a function call, such as id(catch error(badarg)), would not compile with Nera, although the standard Erlang compiler accepts it and runs it.

What changed

  • People who compile such code will notice: it now builds and gives the same results as standard Erlang, for a catch as the first argument of any call or the first element of a tuple.
  • Code that nera fmt rewrote from id((catch X)) to id(catch X) now builds too.
  • A new test checks catch in call arguments and in list and tuple elements, with Nera and with standard Erlang.

Before and after

Before: Of 28 places where a catch can appear, 10 failed to compile with "expected ')', found 'catch'" or "expected '}', found 'catch'"; the other 18 already gave the same results as standard Erlang.

After: All 28 compile and print the same results as standard Erlang (BEAM OTP 29).

The change is in the compiler's parser; nothing on screen changes.

Checked

  • 28 catch positions compiled and run with Nera and with BEAM OTP 29: Before: 10 failed to compile. After: all 28 print the same values as BEAM.
  • New catch_argument_element test: Fails to compile without the fix; passes 20 of 20 runs with Nera, half with one scheduler, and 10 of 10 on BEAM
  • nera fmt output for id((catch error(badarg))): The formatted id(catch error(badarg)) was rejected before and now builds and runs
  • Independent review against BEAM: About 125 more shapes, including macros, maps, records, comprehensions and tail calls, matched; nothing caused by the change
  • Local checks: End-to-end suite (559 passed, 2 skipped) and stacktrace order at this version; lint, Rust tests (2303 passed) and allocator check at the same code before updating from main
How it was checked

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/catch_argument_element.erl and catch_argument_element:test() on OTP 29

Risk

Risk: low in every dimension.

Full risk assessment
Dimension Level Why
Blast radius low One token added to the parser's list of expression starts
Behavior low Code that was rejected now compiles; accepted code parses as before
Undo low Revert the commit
Evidence low Compared end to end with BEAM on 28 positions plus a review of about 125 more
Sensitivity low No saved data, settings or sign-ins
Novelty low Edits existing parser code
Dependencies low No dependencies added or updated

People who compile such code will notice: it now builds and gives the same results as standard Erlang, for a catch as the first argument of any call or the first element of a tuple.

Code that nera fmt rewrote from id((catch X)) to id(catch X) now builds too.

A new test checks catch in call arguments and in list and tuple elements, with Nera and with standard Erlang.
@mremond
mremond merged commit 792dbd2 into main Dec 3, 2026
21 checks passed
@mremond
mremond deleted the infinitary-batch/04019581 branch December 3, 2026 20:08
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