Skip to content

Report an end that closes nothing from the parsed program structure, not a separate line scan - #398

Merged
jbearak merged 2 commits into
mainfrom
refactor/end-diagnostics-ast
Nov 6, 2026
Merged

jbearak merged 2 commits into
mainfrom
refactor/end-diagnostics-ast

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Unexpected end came from the context tracker, which re-derived program and block structure from raw lines with its own regexes, separately from the parser. The two disagreed. On Stata's 3,780 base ados the tracker reported 57 end lines that Stata accepts: the end of input data inside a program, a program's end after code that the tracker misread as opening a block, and lines past a top-level exit, which Stata never reads.

Now the check reads the parsed statements (src/providers/end-diagnostics.ts):

  • UNEXPECTED_END is a top-level end statement that closes nothing. end mata and end python are excluded, since the context tracker still checks those.
  • EMBEDDED_BLOCK_ENDS_PROGRAM comes from the program node's existing ends_at_embedded_block.
  • Checking stops at a top-level exit, but not at capture exit, which Stata reads past.

The parser now ends a program only at an end that begins its line, meaning only whitespace, a /* */ comment or ; comes before it. Legacy ados write } end while to label a closing brace, and that no longer ends the program. The tracker's line-based copies of this logic are removed.

Proof: base ados vs main: 57 UNEXPECTED_END false positives removed, 2 added. Both new ones (export.ado:171, import.ado:261) come from an existing lexer bug: mata : x (with a space) is one-line Mata in Stata, but the lexer opens a Mata block there. That fix changes ~400 unrelated diagnostics, so it's a separate change. Checked in StataMP 18: a stray end, end foo and an extra end; are r(199). Typecheck, lint, and bun test ./tests pass (9661 tests).

Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in T3 Code.

jbearak and others added 2 commits November 5, 2026 18:55
… a program only at an end that begins its line

The context tracker found a stray `end` by scanning raw lines with its
own program and input tracking, which disagreed with the parser and
with Stata. It missed a second `end;` under #delimit ;, `end foo`, and
the program's own `end` after input data in a program (whose `end`
Stata takes as the program's), and it reported mata blocks ending
programs that `mata : x` one-liners never opened. UNEXPECTED_END and
EMBEDDED_BLOCK_ENDS_PROGRAM now come from the AST, in
providers/end-diagnostics.ts, and the raw scan is gone. The parser now
ends a program only at an `end` that begins its line, as the lexer
and Stata do, so `}  end while` in old ado-files no longer cuts a
program short.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 69 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: c47ca221-98ce-435a-9c25-4dd569e9fe67
Commits

Reviewing files that changed from the base of the PR and between 07ed564 and afd9beb.

Files selected for processing: 13

  • docs/diagnostics.md
  • src/context-tracker/index.ts
  • src/parser/index.ts
  • src/providers/diagnostics.ts
  • src/providers/end-diagnostics.ts
  • tests/property/program-block-end-recognition.prop.test.ts
  • tests/property/valid-block-terminators.prop.test.ts
  • tests/test-context-helper.ts
  • tests/unit/context-tracker.test.ts
  • tests/unit/embedded-block-end-rule.test.ts
  • tests/unit/end-diagnostics.test.ts
  • tests/unit/program-embedded-block-end.test.ts
  • tests/unit/program-end-nested.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak merged commit fde808f into main Nov 6, 2026
16 checks passed
@jbearak
jbearak deleted the refactor/end-diagnostics-ast branch November 6, 2026 00:09
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