Skip to content

parser: friendly error for fld used as binding name#225

Merged
danieljohnmorris merged 2 commits into
mainfrom
fix/fld-reserved-error
May 13, 2026
Merged

parser: friendly error for fld used as binding name#225
danieljohnmorris merged 2 commits into
mainfrom
fix/fld-reserved-error

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

fld=5 used to silently parse as a 0-arg call to the fold builtin and surface as ILO-T006 arity mismatch: 'fld' expects 3 or 4 args, got 0. Personas reach for fld as a natural variable (field/fold/folder) and pay the retry tax on a misleading error.

This adds fld to the existing reserved-word friendly-error path that already covers cnt/brk/var/let/if/etc. (the work from 8928635). Same family, same shape, same ILO-P011 code.

Repro

Before:

$ ilo run -e 'f>n;fld=5;p fld'
ILO-T006 arity mismatch: 'fld' expects 3 or 4 args, got 0
ILO-T005 undefined function 'p' (called with 1 args)

After:

$ ilo run -e 'f>n;fld=5;p fld'
ILO-P011 `fld` is reserved for the fold builtin and cannot be used as an identifier
hint: pick a different name like `field` or `folder`

What's in the diff

  • parser: friendly error for fld used as binding name — adds the guard in parse_decl and parse_stmt, mirroring the existing cnt/brk shape so the friendly error fires uniformly at top level and inside function bodies.
  • tests: regression coveragetests/regression_fld_reserved.rs pins the ILO-P011 path under tree/vm/cranelift for both body-level and inside-loop bindings, plus a sanity test that the fld builtin itself still works. A parallel one-liner added to regression_friendly_errors.rs keeps the friendly-error suite the canonical reserved-word audit. examples/fld-reserved-rename.ilo shows the renamed-variable shape an agent should reach for after hitting the error.

Test plan

  • cargo test --release --features cranelift green (all suites)
  • cargo fmt --check clean
  • cargo clippy --release --features cranelift --tests clean
  • Manual repro confirmed before/after across tree/vm/cranelift

Follow-ups

None.

`fld=5` used to cascade through the verifier as
`ILO-T006 arity mismatch: 'fld' expects 3 or 4 args, got 0` because
the parser quietly built a 0-arg call to the fold builtin. Personas
reach for `fld` as a natural variable (field/fold/folder) and pay
the retry tax on a misleading error.

Mirrors the `cnt`/`brk` handling from the original reserved-word
work (commit 8928635). Adds an explicit guard in `parse_decl` and
`parse_stmt`: when an identifier `fld` is followed by `Eq`, emit
ILO-P011 with a rename suggestion (`field`/`folder`) before the
builtin call site has a chance to surface the arity cascade.
Cross-engine regression test pins the new ILO-P011 path under
tree, vm, and cranelift for two shapes: a top-level binding inside
a function body, and a binding inside a `@i` loop. Each asserts
the friendly message, the `field`/`folder` rename hint, and the
absence of the old ILO-T006 arity cascade. A sanity case keeps
the `fld` builtin itself exercised.

Adds a parallel single-line case to `regression_friendly_errors`
alongside the existing `cnt`/`brk` entries so the friendly-error
suite stays the canonical reserved-word audit.

`examples/fld-reserved-rename.ilo` shows the renamed-variable
shape an agent should reach for after hitting the error, and
doubles as a higher-level engine harness regression case.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris merged commit 787bf05 into main May 13, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/fld-reserved-error branch May 13, 2026 12:46
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