parser: friendly error for fld used as binding name#225
Merged
Conversation
`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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fld=5used to silently parse as a 0-arg call to the fold builtin and surface asILO-T006 arity mismatch: 'fld' expects 3 or 4 args, got 0. Personas reach forfldas a natural variable (field/fold/folder) and pay the retry tax on a misleading error.This adds
fldto the existing reserved-word friendly-error path that already coverscnt/brk/var/let/if/etc. (the work from 8928635). Same family, same shape, same ILO-P011 code.Repro
Before:
After:
What's in the diff
fldused as binding name — adds the guard inparse_declandparse_stmt, mirroring the existingcnt/brkshape so the friendly error fires uniformly at top level and inside function bodies.tests/regression_fld_reserved.rspins the ILO-P011 path under tree/vm/cranelift for both body-level and inside-loop bindings, plus a sanity test that thefldbuiltin itself still works. A parallel one-liner added toregression_friendly_errors.rskeeps the friendly-error suite the canonical reserved-word audit.examples/fld-reserved-rename.iloshows the renamed-variable shape an agent should reach for after hitting the error.Test plan
cargo test --release --features craneliftgreen (all suites)cargo fmt --checkcleancargo clippy --release --features cranelift --testscleanFollow-ups
None.