Skip to content

diag: don't fire prefix-precedence hint inside parens#309

Merged
danieljohnmorris merged 2 commits into
mainfrom
fix/precedence-hint-no-parens-fp
May 16, 2026
Merged

diag: don't fire prefix-precedence hint inside parens#309
danieljohnmorris merged 2 commits into
mainfrom
fix/precedence-hint-no-parens-fp

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

PR #301's same-precedence prefix-pair trap hint (*/, /*, +-, -+) fires on the parenthesised form too, e.g. (/ *errs 100 tot). That's the recommended disambiguation shape, so flagging it contradicts the hint's own advice and spams every rate-calc program on every run. Streaming-tail rerun4 surfaced this as a false-positive papercut.

Repro

Before:

$ ilo 'rate errs:n tot:n>n;(/ *errs 100 tot)' rate 3 12
25
{"hints":["hint: `/*a b c` parses as `(a*b)/c` (inner prefix op binds first). For the other order, swap the ops (`*/a b c`) or bind: `r=/a b;*r c`"]}

After:

$ ilo 'rate errs:n tot:n>n;(/ *errs 100 tot)' rate 3 12
25

Bare unparenthesised form still fires as before.

What's in the diff

  • diag: suppress prefix-precedence hint inside explicit parens — in detect_prefix_precedence_trap (src/main.rs), skip when the immediate predecessor of op1 is LParen. Token-local, one extra guard. Covers nested parens (((*/ a b c))) because the immediate predecessor is still LParen. Adds four unit + integration tests: paren-grouped pair (all four shapes), nested parens, bare form still fires, unit-level detector pin.
  • example: parenthesised prefix pair runs silentexamples/prefix-pair-in-parens.ilo exercises the rate-calc shape under the engine harness via -- run: / -- out: assertions.

Test plan

  • cargo build --release --features cranelift
  • cargo test --release --features cranelift — full suite, 0 failures
  • cargo clippy --release --features cranelift --all-targets -- -D warnings — clean
  • cargo fmt --check — clean
  • Manual repro: (/ *errs 100 tot) silent, bare */a b c still emits the hint
  • All four pair shapes (*/, /*, +-, -+) suppressed inside parens
  • Nested parens ((*/ a b c)) suppressed

The same-precedence prefix-pair trap hint (`*/`, `/*`, `+-`, `-+`) added
in #301 fires on the parenthesised form too, e.g. `(/ *errs 100 tot)`.
That's the recommended disambiguation shape, so flagging it contradicts
the hint's own advice and spams every rate-calc program on every run.

Suppress when the immediate predecessor of op1 is `LParen`. Token-local,
covers nested parens (`((*/ a b c))`) because the immediate predecessor
is still `LParen`.

Bare unparenthesised form continues to fire.
`(/ *errs 100 tot)` is the canonical rate-calc shape and now emits no
hint. Engine harness picks it up via the `-- run:` / `-- out:` assertion
as a higher-level regression test.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 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 0e2947b into main May 16, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/precedence-hint-no-parens-fp branch May 16, 2026 16:57
danieljohnmorris added a commit that referenced this pull request May 16, 2026
twelve fixes since 0.11.3, surfaced by rerun4 personas plus standing asks: srt-Cranelift TLS desync (#306), CLI auto-run restoration (#307), OP_LISTAPPEND O(n^2) JIT memory regression (#308), precedence-pair hint false-positive on parens (#309), prefix ?? accepts call expression (#310), += pure-shape docs (#311), bare-mutation silent no-op verifier warning ILO-T033 (#312), asin/acos/atan inverse trig builtins (#313), flat cross-engine (#314), cond{~v} discard hint multi-stmt false-positive (#315), rsrt fn xs key-fn overloads (#316), xs.(expr) paren-after-dot diagnostic hint (#317).
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