Skip to content

fix(explain): retain iteration source across statement boundaries - #991

Merged
Anand Krishnamoorthi (anakrish) merged 1 commit into
microsoft:mainfrom
snehabandla:fix/explain-iteration-boundaries
Nov 24, 2026
Merged

Anand Krishnamoorthi (anakrish) merged 1 commit into
microsoft:mainfrom
snehabandla:fix/explain-iteration-boundaries

Conversation

@snehabandla

Copy link
Copy Markdown
Collaborator

Summary

Preserve iteration source text and locations when an equal-length alternative crosses into a following statement.

Reject recovery candidates containing top-level semicolons or adjacent operands, including separate array/set expressions. Treat signed-number tokens as subtraction continuations so candidates cannot stop before an unspaced subtraction. Preserve existing grouping, keyword-shaped operands, references, and spaced, multiline or string-indexed function calls.

Compatibility

Only explanation source metadata changes. No policy evaluation, public API or serialization changes.

Related

Follows #971.

Testing

  • Source-boundary regressions reproduced before correction, with grouped and spaced-subtraction controls.
  • Provenance tests with default and minimal explanation-enabled feature configurations.
  • Library and integration suites with explanations enabled and disabled.
  • Mutation check confirms the new boundary test detects removal of trailing-operator validation.
  • Formatting, all-feature/all-target and no-default-feature Clippy, and explanation-enabled doctests.

Reject equal-length recovery candidates spanning statement separators or adjacent operands and signed-number subtraction boundaries. Preserve grouping, keyword operands and valid call/reference continuations, with focused source-location regressions and mutation-proven trailing-operator coverage.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The call exemption misclassifies parentheses after non-callable terms, allowing an incorrect alternative match that loses the iteration’s source text and location.

1 open issue
What changed in this PR

This follow-up to #971 tightens explanation provenance recovery to preserve iteration source text and locations across statement boundaries, without changing policy evaluation or public APIs.

Changes:

  • Reject candidate spans that cross statement separators or adjacent operands, and recognize signed-number subtraction continuations.
  • Add boundary regressions and controls for grouping, spaced subtraction, and spaced, multiline, and indirect calls.
File Description
src/​explain/​provenance/​tests.rs Adds source-text and location regressions plus call-format controls.
src/​explain/​provenance.rs Strengthens token-boundary checks used to recover iteration expression spans.

Review effort: Max

Comment thread src/explain/provenance.rs
if depth == 0
&& bracket == 1
&& follows_operand
&& self.symbol(index) != Some("(")
@anakrish
Anand Krishnamoorthi (anakrish) merged commit 983dab9 into microsoft:main Nov 24, 2026
61 checks passed
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.

3 participants