add ILO-P102 hint for top-level bindings without main wrapper#513
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
When an agent writes a top-level chain like pts=gen-pts;cs0=[...];cs1=iter cs0 pts;prnt cs1 without wrapping it in a function header, the parser used to either die on the bare = (a bare ILO-P003 with no actionable hint) or, when a prior name>type;body declaration was in scope, slurp the chain into that fn's body and emit a wall of misleading ILO-T005 cascades anchored on the wrong line. K-means and linear-regression personas both hit this. Two parser changes collapse both shapes into a single diagnostic: - can_start_operand refuses to cross an un-indented newline into an Ident= binding shape, so the prior fn's body can't slurp the orphan chain as a call argument. - parse_decl recognises a bare Ident= at the top level (after the existing reserved-keyword / builtin / alias guards) and emits ILO-P102 with the main>_; wrapper hint. Parser-only, identical output across VM and JIT.
Cross-engine regression on the two repro shapes (bare top-level chain and chain slurped into a prior fn body), plus a passing example that shows the main>_; wrapper running cleanly. The example doubles as agent-facing learning material for what the corrected form looks like.
CHANGELOG entry under Unreleased > Added and a row in the SPEC cross-language gotchas table pointing at the main>_; wrapper fix.
Picks up the new ILO-P102 row in the cross-language gotchas table.
7b2906f to
ccb2eb2
Compare
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
K-means and linear-regression personas both got stuck on the same misparse this week: a top-level imperative chain written without a `main>_;` wrapper. The parser either died on the bare `=` (a bare ILO-P003 with no actionable hint) or, when a prior `name>type;body` decl was in scope, slurped the whole chain into that fn's body and emitted a wall of misleading ILO-T005 cascades anchored on the wrong line. K-means hit the 600s watchdog because of the cascade. Pending #5aj.
This adds ILO-P102, which catches the shape at parse time and points at the `main>_;` fix.
Repro before/after
```
gen-pts>L(L n);[[2.0 3.0][8.0 8.0][0.5 0.5]]
iter cs:L(L n) pts:L(L n)>L(L n);cs
pts=gen-pts;cs0=[[4.8 4.9][6.2 7.1][1.0 1.0]];cs1=iter cs0 pts;cs2=iter cs1 pts;prnt cs2
```
Before (2 diagnostics, anchored on the wrong function):
```
ILO-T005: 'cs' is a L L n, not a function (called with 1 args) (in function 'iter')
ILO-T039: 'gen-pts' is a 0-arg function used as a value reference, not a call (in function 'iter')
```
After (1 diagnostic, anchored on the orphan line):
```
ILO-P102: top-level `pts=...` binding outside any function declaration
hint: ilo programs need a function header. Wrap imperative chains in `main>;`
(e.g. `main>;pts=...;...;prnt result`) or give this binding a proper
signature like `pts>n;`
```
What's in the diff
Parser-only change; output is identical across VM and JIT.
Test plan
Follow-ups