Skip to content

fix: scan source tokens for alias hints, not raw text#253

Merged
danieljohnmorris merged 3 commits into
mainfrom
fix/tail-alias-source-only
May 13, 2026
Merged

fix: scan source tokens for alias hints, not raw text#253
danieljohnmorris merged 3 commits into
mainfrom
fix/tail-alias-source-only

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

collect_hints was splitting raw source text after stripping string literals, but comments (-- ...) were left in. Any alias source word in a comment, identifier-ish artefact, or path-bearing line could fire hint: <word> -> <short> even though the user never wrote that token.

Streaming-tail persona on v0.11.1 caught this every Approach B run: hint: tail -> tl fired because the working directory was /tmp/ilo-persona-streaming-tail-rerun, and the path leaked into the batch script's header comment. Cosmetic but noisy in pipelines, and exactly the kind of false-positive that erodes trust in agent-facing hints.

Fix: re-lex inside collect_hints and scan Token::Ident only. Correct by construction — comments, strings, numbers, operators, and CLI argv all sit outside the token stream the user wrote. The == text-scan now also ignores comment contents via a small helper, so both hints behave consistently.

Repro

-- counts: tail of error log
main>n;42

Before: hint: \tail` → `tl` (canonical short form) printed to stderr on every run. After: no hint. Real alias use (tail xs` as a source identifier) still fires.

What's in the diff

  • 9fc9785 fix: collect_hints re-lexes the source and walks Token::Ident. New helper strip_string_and_comment_contents keeps the == scan consistent (logos collapses = and == to one token, so that scan can't use lexer output).
  • 583e04f test: five new regression tests pin the contract: alias word in comment, alias word in string, the == scan in comments, multi-word coverage across tail/filter/flatmap/length/head/append, and a positive test that real alias use still fires.
  • 7e79f9c example: examples/tail-alias-comment.ilo shows an idiomatic no-hint program with tail in both a comment and a string literal. Multi-engine harness runs it on every backend.

Test plan

  • cargo test --release --features cranelift — full suite green (2888 lib + all integration)
  • cargo fmt --check clean
  • cargo clippy --release --features cranelift -- -D warnings clean
  • cargo test --test examples_engines passes (including the new example)
  • Manual repro: tail in comment / string / path no longer fires; tail xs as a real call still fires.

Follow-ups

None planned. The lexer-token approach generalises to any future builtin alias added to ast::resolve_alias.

collect_hints previously split the source text on non-word chars after
stripping string literals, but comments (`-- ...`) were not stripped.
Any alias source word appearing in a comment, in a path-bearing identifier,
or in any non-token context would fire `hint: <word> -> <short>`.

Surfaced by the streaming-tail persona on v0.11.1: every Approach B
invocation got `hint: tail -> tl` because the working directory was
/tmp/ilo-persona-streaming-tail-rerun, and that path made it into the
batch script header as a comment.

Re-lex the source and scan Token::Ident only. Correct by construction:
comments, strings, numbers, operators, and CLI argv are all outside the
token stream the user wrote. As a side-effect the text-based `==` scan
now also ignores comment contents via a small helper, so the equality
hint is consistent with the alias hint.
Five new tests pin the lexer-token contract: alias words in comments,
in string literals, and the `==` hint in comments must all return no
hints; real alias use (`tail xs` as a source identifier) must still
fire. Iterate over a representative set of alias source words to catch
regression on the others (filter, flatmap, length, head, append).
Shows that `tail` in a comment and inside a string literal does not
fire the alias hint, while the canonical `tl` form is used in source.
Picked up by tests/examples_engines.rs as a multi-engine assertion.
@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 d2ab946 into main May 13, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/tail-alias-source-only branch May 13, 2026 19:28
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