Skip to content

fix(parser): reject binary comprehension bodies written as segments - #85

Merged
mremond merged 1 commit into
mainfrom
inf/binary-comprehension-body-silently-loses-its-8d41
Nov 22, 2026
Merged

mremond merged 1 commit into
mainfrom
inf/binary-comprehension-body-silently-loses-its-8d41

Conversation

@mremond

@mremond mremond commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

A binary comprehension body written with a size or type compiled and silently lost them, although the Erlang compiler rejects this form.

What changed

  • A body with a size, a type or several segments is now a compile error that shows how to write it.
  • A bare remote call as the body is now a compile error instead of a call that never runs.
  • The formatter leaves these bodies as written instead of deleting their size, type or call.

Before and after

Before: << X:16 || X <- [<<1>>] >> compiled and returned <<1>>, and << erlang:error(boom) || _ <- [a] >> raised badarg without making the call.

After: Both programs stop at compile time with an error on the body, and no executable is written.

This changes compiler errors and formatter output in the terminal, so there is no screen to picture.

Checked

  • 50 comprehension body forms compared with the Erlang/OTP 29 compiler: Agreement rose from 25 to 44 forms; every form with a size, type or several segments is now rejected, and every valid form still compiles.
  • The two reported programs built before and after the change: Before, they printed <<1>> and badarg; after, each build fails with the new error and writes no executable.
  • Formatter output on all 818 Erlang files in the repository, before and after: No file differs.
  • Lint and the Rust workspace tests: Lint passed; 2,253 tests passed, none failed, one is ignored.
  • The end-to-end suite on macOS arm64: 543 passed, none failed, 2 skipped.
  • The new regression tests, ten runs in a row: All ten runs passed.
How it was checked

Compared accepted and rejected forms against erlc from Erlang/OTP 29.

Ran cargo clippy with warnings denied, cargo test across the workspace and the end-to-end suite.

Risk

Risk above low: Behavior, high — Code erlc rejects used to compile here and now stops the build.

Full risk assessment
Dimension Level Why
Blast radius low One parser branch, reached only by binary comprehensions.
Behavior high Code erlc rejects used to compile here and now stops the build.
Undo low Reverting the commit restores the old behavior.
Evidence low Real programs and 50 forms were compared with erlc.
Sensitivity low Touches no data, settings or credentials.
Novelty low A small check in existing parser code.
Dependencies low Adds and updates no package.
Not done

Bare calls, signed numbers, maps and records as bodies still compile although erlc rejects them; their values are kept, and a separate follow-up covers them.

@github-actions github-actions Bot added this to the 0.1.1 milestone Nov 22, 2026
@mremond
mremond merged commit e93d32e into main Nov 22, 2026
22 checks passed
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