Skip to content

fix(fmt): preserve grouping of negated negative literals - #47

Merged
mremond merged 1 commit into
mainfrom
fm/task-d98784fa
Nov 15, 2026
Merged

mremond merged 1 commit into
mainfrom
fm/task-d98784fa

Conversation

@mremond

@mremond mremond commented Nov 14, 2026

Copy link
Copy Markdown
Member

Why

Formatting negated negative literals must produce valid Erlang and remain unchanged on a second pass.

What changed

  • Keep parentheses around negative literal operands, including integer zero and arbitrary-size integers.
  • Preserve numeric values and literal spelling through repeated formatting.

Before and after

Before: Both representative expressions formatted into invalid list-subtraction tokens: --0 and --99999999999999999999.

After: Both expressions retain valid grouping; thirteen CLI examples compile with identical values on Erlang/OTP.

This changes formatted Erlang source, not an on-screen view; CLI output and OTP compilation demonstrate the result.

Checked

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

Scenario Result Evidence
Format negated negative zero and arbitrary-size negative literals, then format again and compile both sources. ✅ Passed live Real formatter CLI output, byte-identical second pass, successful format check and OTP compilation with identical encoded values across thirteen expressions.
  • Formatter CLI and Erlang/OTP comparison: Thirteen expressions retain identical encoded values; a second formatting pass is byte-identical and the format check passes.
  • New regression target: Both tests reproduce failures before the fix and pass ten consecutive runs after it.
  • Local project gate: Release builds, strict Clippy, allocator and stacktrace checks pass; 2,187 Rust tests and 496 native tests pass.
  • Independent review: The committed correction and recorded live proof have no blocking findings.
How it was checked

cargo test --locked -p nera-fmt --test negative_literals; ten consecutive runs without retries

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: 2,187 passed, one ignored

./target/release/nera test -j 1 --timeout 30: 496 passed, two external-module skips

python3 scripts/test-allocator-config.py; python3 scripts/test-stacktrace-order.py

Real formatter CLI, repeated formatting, format check, and original/formatted OTP compilation and encoded-value comparison

Risk

Risk: low in every dimension.

Full risk assessment
Dimension Level Why
Blast radius low Only unary numeric operand grouping changes.
Behavior low Corrects invalid formatter output without changing program values.
Undo low Revert the commit; no data migration is involved.
Evidence low Real formatter output compiles on OTP and preserves encoded values.
Sensitivity low No accounts, keys, payments or saved settings are touched.
Novelty low Uses the existing source-spelling approach for numeric literals.
Dependencies low No dependency changes.

Pipeline

Updates from git push no-mistakes

Infinitary checked this version: an independent review that also judged the documents, and live validation the review accepted.

@github-actions github-actions Bot added this to the 0.1.1 milestone Nov 14, 2026
@mremond
mremond merged commit 2457f79 into main Nov 15, 2026
15 checks passed
@mremond
mremond deleted the fm/task-d98784fa branch November 15, 2026 14:05
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